diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml
index 3cd311d501..cc2d710782 100644
--- a/.github/actions/install/action.yml
+++ b/.github/actions/install/action.yml
@@ -1,8 +1,15 @@
name: Install
description: Set up Node.js, Corepack, and install dependencies with yarn cache
+# The Blacksmith condition must match the runner selection in workflows/ci.yml.
runs:
using: composite
steps:
+ - name: Mount Node.js toolcache
+ if: ${{ github.repository_owner == 'outline' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
+ uses: useblacksmith/stickydisk@94697d49e77d0dd78b77deb85ad3de63a28b4b8a # v1.7.1
+ with:
+ key: ${{ github.repository }}-node-toolcache
+ path: /opt/hostedtoolcache/node
- name: Enable Corepack
shell: bash
run: corepack enable
@@ -10,7 +17,20 @@ runs:
uses: actions/setup-node@v5
with:
node-version: 26.x
- cache: "yarn"
+ # Blacksmith jobs persist the yarn cache on a sticky disk instead.
+ package-manager-cache: ${{ !(github.repository_owner == 'outline' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) }}
+ - name: Mount yarn cache
+ if: ${{ github.repository_owner == 'outline' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
+ uses: useblacksmith/stickydisk@94697d49e77d0dd78b77deb85ad3de63a28b4b8a # v1.7.1
+ with:
+ key: ${{ github.repository }}-yarn-cache
+ path: ~/.yarn/berry/cache
+ - name: Mount node_modules
+ if: ${{ github.repository_owner == 'outline' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
+ uses: useblacksmith/stickydisk@94697d49e77d0dd78b77deb85ad3de63a28b4b8a # v1.7.1
+ with:
+ key: ${{ github.repository }}-node-modules
+ path: ./node_modules
- name: Install dependencies
shell: bash
run: yarn install --immutable
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ba95754024..d763a546ac 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -18,8 +18,12 @@ env:
jobs:
changes:
- runs-on: ubuntu-latest
+ # Blacksmith runners are only available to the outline organization, and are
+ # not used for pull requests from forks so that fork-controlled code cannot
+ # write to the shared sticky disks. Keep in sync with actions/install.
+ runs-on: ${{ (github.repository_owner == 'outline' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-latest' }}
outputs:
+ runner: ${{ (github.repository_owner == 'outline' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) && 'blacksmith-8vcpu-ubuntu-2404' || 'ubuntu-latest' }}
code: ${{ steps.filter.outputs.code }}
config: ${{ steps.filter.outputs.config }}
server: ${{ steps.filter.outputs.server }}
@@ -60,7 +64,7 @@ jobs:
lint:
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
- runs-on: ubuntu-latest
+ runs-on: ${{ needs.changes.outputs.runner }}
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/install
@@ -79,7 +83,7 @@ jobs:
types:
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
- runs-on: ubuntu-latest
+ runs-on: ${{ needs.changes.outputs.runner }}
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/install
@@ -88,7 +92,7 @@ jobs:
audit:
needs: changes
if: ${{ needs.changes.outputs.deps == 'true' }}
- runs-on: ubuntu-latest
+ runs-on: ${{ needs.changes.outputs.runner }}
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/install
@@ -97,7 +101,7 @@ jobs:
test:
needs: changes
if: ${{ needs.changes.outputs.app == 'true' || needs.changes.outputs.config == 'true' }}
- runs-on: ubuntu-latest
+ runs-on: ${{ needs.changes.outputs.runner }}
strategy:
matrix:
test-group: [app, shared]
@@ -109,37 +113,30 @@ jobs:
test-server:
needs: changes
if: ${{ needs.changes.outputs.server == 'true' || needs.changes.outputs.config == 'true' }}
- runs-on: ubuntu-latest
- services:
- postgres:
- image: postgres:14.2
- env:
- POSTGRES_USER: postgres
- POSTGRES_PASSWORD: password
- POSTGRES_DB: outline_test
- ports:
- - 5432:5432
- options: >-
- --health-cmd pg_isready
- --health-interval 10s
- --health-timeout 5s
- --health-retries 5
-
+ runs-on: ${{ needs.changes.outputs.runner }}
strategy:
matrix:
- shard: [1, 2, 3, 4]
+ shard: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/checkout@v5
+ # The runner image ships with PostgreSQL preinstalled, starting it is much
+ # faster than pulling and initializing a service container.
+ - name: Start PostgreSQL
+ run: |
+ sudo systemctl start postgresql.service
+ until pg_isready -h localhost; do sleep 1; done
+ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"
+ sudo -u postgres createdb outline_test
- uses: ./.github/actions/install
- run: yarn sequelize db:migrate
- name: Run server tests
- run: yarn test:server --maxWorkers=2 --shard=${{ matrix.shard }}/4
+ run: yarn test:server --maxWorkers=4 --shard=${{ matrix.shard }}/6
bundle-size:
needs: changes
if: ${{ (needs.changes.outputs.app == 'true' || needs.changes.outputs.config == 'true') && github.repository == 'outline/outline' }}
- runs-on: ubuntu-latest
+ runs-on: ${{ needs.changes.outputs.runner }}
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/install
diff --git a/.oxlintrc.json b/.oxlintrc.json
index 5cc0cbd062..203bd0254f 100644
--- a/.oxlintrc.json
+++ b/.oxlintrc.json
@@ -70,6 +70,12 @@
"valid-typeof": "error"
},
"overrides": [
+ {
+ "files": ["**/*.{ts,tsx}"],
+ "rules": {
+ "no-redeclare": "off"
+ }
+ },
{
"files": ["**/*.{js,jsx,ts,tsx}"],
"rules": {
diff --git a/AGENTS.md b/AGENTS.md
index 7618999693..0fe213fa37 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -168,6 +168,7 @@ yarn test:shared # All shared code tests
```
- Write unit tests for utilities and business logic in a collocated .test.ts file.
+- Server tests share a module registry between files. A server test that uses `vi.mock` or `vi.resetModules` must start with `// @vitest-isolate true` so it runs isolated.
- Do not create new test directories
- Mock external dependencies appropriately in **mocks** folder.
- Aim for high code coverage but focus on critical paths.
diff --git a/LICENSE b/LICENSE
index 3ba5896f6a..494e025dfb 100644
--- a/LICENSE
+++ b/LICENSE
@@ -3,7 +3,7 @@ Business Source License 1.1
Parameters
Licensor: General Outline, Inc.
-Licensed Work: Outline 1.10.0
+Licensed Work: Outline 1.10.1
The Licensed Work is (c) 2026 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: 2030-09-01
+Change Date: 2030-09-09
Change License: Apache License, Version 2.0
diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx
index 0e4c901c3a..5c10094009 100644
--- a/app/actions/definitions/documents.tsx
+++ b/app/actions/definitions/documents.tsx
@@ -63,6 +63,7 @@ import DocumentPublish from "~/scenes/DocumentPublish";
import DeleteDocumentsInTrash from "~/scenes/Trash/components/DeleteDocumentsInTrash";
import ConfirmationDialog from "~/components/ConfirmationDialog";
import { DialogTitle } from "~/components/DialogTitle";
+import { DocumentArchiveDialog } from "~/components/DocumentArchiveDialog";
import DocumentCopy from "~/components/DocumentExplorer/DocumentCopy";
import MarkdownIcon from "~/components/Icons/MarkdownIcon";
import { ImportDocumentDialog } from "~/components/ImportDocumentDialog";
@@ -742,10 +743,20 @@ export const shareDocument = createAction({
},
});
+/**
+ * Shows a file extension in the shortcut slot of menu items only, the command
+ * bar would otherwise register it as a key sequence.
+ */
+const fileExtensionHint =
+ (extension: string) =>
+ ({ isMenu }: ActionContext) =>
+ isMenu ? [extension] : undefined;
+
export const downloadDocumentAsMarkdown = createAction({
name: ({ t, isMenu }) => (isMenu ? t("Markdown") : t("Download as Markdown")),
analyticsName: "Download document as Markdown",
section: ActiveDocumentSection,
+ shortcut: fileExtensionHint(".md"),
keywords: "md markdown export download",
icon: ,
iconInContextMenu: false,
@@ -767,6 +778,7 @@ export const downloadDocumentAsHTML = createAction({
name: ({ t, isMenu }) => (isMenu ? t("HTML") : t("Download as HTML")),
analyticsName: "Download document as HTML",
section: ActiveDocumentSection,
+ shortcut: fileExtensionHint(".html"),
keywords: "xml html export download",
icon: ,
iconInContextMenu: false,
@@ -789,6 +801,7 @@ export const downloadDocumentAsTextBundle = createAction({
isMenu ? t("TextBundle") : t("Download as TextBundle"),
analyticsName: "Download document as TextBundle",
section: ActiveDocumentSection,
+ shortcut: fileExtensionHint(".textpack"),
keywords: "textbundle textpack bear ulysses export download",
icon: ,
iconInContextMenu: false,
@@ -810,6 +823,7 @@ export const downloadDocumentAsPDF = createAction({
name: ({ t, isMenu }) => (isMenu ? t("PDF") : t("Download as PDF")),
analyticsName: "Download document as PDF",
section: ActiveDocumentSection,
+ shortcut: fileExtensionHint(".pdf"),
keywords: "pdf export download",
icon: ,
iconInContextMenu: false,
@@ -1173,6 +1187,7 @@ export const printDocument = createAction({
name: ({ t, isMenu }) => (isMenu ? t("Print") : t("Print document")),
analyticsName: "Print document",
section: ActiveDocumentSection,
+ shortcut: ["Meta+P"],
icon: ,
iconInContextMenu: false,
visible: ({ activeDocumentId }) => !!(activeDocumentId && window.print),
@@ -1473,10 +1488,11 @@ export const archiveDocument = createAction({
})
),
content: (
- {
+ {
const succeeded = await performBatch(documents, (document) =>
- document.archive()
+ document.archive({ reason })
);
if (succeeded) {
toast.success(
@@ -1486,16 +1502,7 @@ export const archiveDocument = createAction({
);
}
}}
- savingText={`${t("Archiving")}…`}
- >
- {documents.length === 1
- ? t(
- "Archiving this document will remove it from the collection and search results."
- )
- : t(
- "Archiving these documents will remove them from their collections and search results."
- )}
-
+ />
),
});
},
diff --git a/app/actions/index.ts b/app/actions/index.ts
index 46decda4fb..37cbcca3e7 100644
--- a/app/actions/index.ts
+++ b/app/actions/index.ts
@@ -46,24 +46,7 @@ export function createAction(
...definition,
type: "action",
variant: "action",
- perform: definition.perform
- ? (context) => {
- // We must use the specific analytics name here as the action name is
- // translated and potentially contains user strings.
- if (definition.analyticsName) {
- Analytics.track("perform_action", definition.analyticsName, {
- context: context.isButton
- ? "button"
- : context.isCommandBar
- ? "commandbar"
- : context.isMCP
- ? "webmcp"
- : "contextmenu",
- });
- }
- return definition.perform(context);
- }
- : () => {},
+ perform: definition.perform ?? (() => {}),
id: definition.id ?? uuidv4(),
};
}
@@ -182,7 +165,7 @@ export function actionToMenuItem(
icon,
visible,
disabled,
- tooltip: resolve(action.tooltip, context),
+ tooltip: resolve(action.tooltip, context),
selected: resolve(action.selected, context),
dangerous: action.dangerous,
shortcut,
@@ -353,6 +336,20 @@ export async function performAction(
? () => history.push(resolve(action.to, context))
: () => window.open(action.url, action.target);
+ // We must use the specific analytics name here as the action name is
+ // translated and potentially contains user strings.
+ if (action.analyticsName) {
+ Analytics.track("perform_action", action.analyticsName, {
+ context: context.isButton
+ ? "button"
+ : context.isCommandBar
+ ? "commandbar"
+ : context.isMCP
+ ? "webmcp"
+ : "contextmenu",
+ });
+ }
+
const result = perform();
if (result instanceof Promise) {
diff --git a/app/components/ActionButton.tsx b/app/components/ActionButton.tsx
index e42f45bfba..f1650bbc1d 100644
--- a/app/components/ActionButton.tsx
+++ b/app/components/ActionButton.tsx
@@ -22,68 +22,67 @@ export type Props = React.HTMLAttributes & {
/**
* Button that can be used to trigger an action definition.
*/
-const ActionButton = React.forwardRef(
- function ActionButton_(
- { action, tooltip, hideOnActionDisabled, ...rest }: Props,
- ref: React.Ref
- ) {
- const actionContext = useActionContext({
- isButton: true,
- });
- const isMounted = useIsMounted();
- const [executing, setExecuting] = React.useState(false);
+function ActionButton({
+ action,
+ tooltip,
+ hideOnActionDisabled,
+ ref,
+ ...rest
+}: Props & { ref?: React.Ref }) {
+ const actionContext = useActionContext({
+ isButton: true,
+ });
+ const isMounted = useIsMounted();
+ const [executing, setExecuting] = React.useState(false);
- if (!actionContext || !action) {
- return ;
- }
-
- const actionIsDisabled =
- action.visible && !resolve(action.visible, actionContext);
-
- if (actionIsDisabled && hideOnActionDisabled) {
- return null;
- }
-
- const disabled = rest.disabled || actionIsDisabled;
-
- const label =
- rest["aria-label"] ??
- (typeof action.name === "function"
- ? action.name(actionContext)
- : action.name);
-
- const button = (
-
- );
-
- if (tooltip) {
- return {button};
- }
-
- return button;
+ if (!actionContext || !action) {
+ return ;
}
-);
+
+ const actionIsDisabled =
+ action.visible && !resolve(action.visible, actionContext);
+
+ if (actionIsDisabled && hideOnActionDisabled) {
+ return null;
+ }
+
+ const disabled = rest.disabled || actionIsDisabled;
+
+ const label =
+ rest["aria-label"] ??
+ (typeof action.name === "function"
+ ? action.name(actionContext)
+ : action.name);
+
+ const button = (
+
+ );
+
+ if (tooltip) {
+ return {button};
+ }
+
+ return button;
+}
export default observer(ActionButton);
diff --git a/app/components/ArrowKeyNavigation.tsx b/app/components/ArrowKeyNavigation.tsx
index 7834efd5aa..7e520998b3 100644
--- a/app/components/ArrowKeyNavigation.tsx
+++ b/app/components/ArrowKeyNavigation.tsx
@@ -6,12 +6,16 @@ type Props = Omit, "children"> & {
children: () => React.ReactNode;
onEscape?: (ev: React.KeyboardEvent) => void;
items: unknown[];
+ ref?: React.Ref;
};
-function ArrowKeyNavigation(
- { children, onEscape, items, ...rest }: Props,
- ref: React.RefObject
-) {
+function ArrowKeyNavigation({
+ children,
+ onEscape,
+ items,
+ ref,
+ ...rest
+}: Props) {
const handleKeyDown = React.useCallback(
(ev: React.KeyboardEvent) => {
if (onEscape) {
@@ -48,4 +52,4 @@ function ArrowKeyNavigation(
);
}
-export default observer(React.forwardRef(ArrowKeyNavigation));
+export default observer(ArrowKeyNavigation);
diff --git a/app/components/Authenticated.tsx b/app/components/Authenticated.tsx
index 9a50239400..734904f6ee 100644
--- a/app/components/Authenticated.tsx
+++ b/app/components/Authenticated.tsx
@@ -8,7 +8,7 @@ import { changeLanguage } from "~/utils/language";
import LoadingIndicator from "./LoadingIndicator";
type Props = {
- children: JSX.Element;
+ children: React.JSX.Element;
};
const Authenticated = ({ children }: Props) => {
diff --git a/app/components/Avatar/Avatar.tsx b/app/components/Avatar/Avatar.tsx
index 18abcd4b9f..34edf124cd 100644
--- a/app/components/Avatar/Avatar.tsx
+++ b/app/components/Avatar/Avatar.tsx
@@ -49,16 +49,16 @@ export type AvatarProps = {
showTooltip?: boolean;
/** Whether to show a profile card on hover for users, defaults to true */
showHoverCard?: boolean;
+ /** Ref to the outer element */
+ ref?: React.Ref;
} & Omit<
React.ComponentPropsWithoutRef<"div">,
"onClick" | "className" | "style"
>;
-const Avatar = React.forwardRef(function Avatar_(
- props: AvatarProps,
- ref: React.Ref
-) {
+function Avatar(props: AvatarProps) {
const {
+ ref,
model,
style,
variant = AvatarVariant.Round,
@@ -111,7 +111,7 @@ const Avatar = React.forwardRef(function Avatar_(
) : (
content
);
-});
+}
const Relative = styled.div<{ $variant: AvatarVariant; $size: AvatarSize }>`
position: relative;
diff --git a/app/components/Avatar/AvatarWithHoverCard.tsx b/app/components/Avatar/AvatarWithHoverCard.tsx
index 64f8000bfc..8ffb3c3a70 100644
--- a/app/components/Avatar/AvatarWithHoverCard.tsx
+++ b/app/components/Avatar/AvatarWithHoverCard.tsx
@@ -1,5 +1,4 @@
import { observer } from "mobx-react";
-import * as React from "react";
import { UserHoverCard } from "~/components/UserHoverCard";
import User from "~/models/User";
import type { AvatarProps } from "./Avatar";
@@ -9,10 +8,12 @@ import Avatar from "./Avatar";
* An avatar that additionally displays a profile card on hover when the model
* it represents is a user.
*/
-const AvatarWithHoverCard = React.forwardRef(function AvatarWithHoverCard_(
- { showTooltip, showHoverCard = true, ...props }: AvatarProps,
- ref: React.Ref
-) {
+function AvatarWithHoverCard({
+ showTooltip,
+ showHoverCard = true,
+ ref,
+ ...props
+}: AvatarProps) {
const { model } = props;
if (!showHoverCard || !(model instanceof User)) {
@@ -24,6 +25,6 @@ const AvatarWithHoverCard = React.forwardRef(function AvatarWithHoverCard_(
);
-});
+}
export default observer(AvatarWithHoverCard);
diff --git a/app/components/Breadcrumb.tsx b/app/components/Breadcrumb.tsx
index 7a9296ddd3..4a4b98aeb7 100644
--- a/app/components/Breadcrumb.tsx
+++ b/app/components/Breadcrumb.tsx
@@ -20,12 +20,16 @@ type Props = React.PropsWithChildren<{
actions: InternalLinkAction[];
max?: number;
highlightFirstItem?: boolean;
+ ref?: React.Ref;
}>;
-function Breadcrumb(
- { actions, highlightFirstItem, children, max = 2 }: Props,
- ref: React.RefObject | null
-) {
+function Breadcrumb({
+ actions,
+ highlightFirstItem,
+ children,
+ max = 2,
+ ref,
+}: Props) {
const actionContext = useActionContext({ isMenu: true });
const visibleActions = useComputed(
@@ -141,4 +145,4 @@ const Title = styled.span`
min-width: 0;
`;
-export default observer(React.forwardRef(Breadcrumb));
+export default observer(Breadcrumb);
diff --git a/app/components/Button.tsx b/app/components/Button.tsx
index 75a2b0b622..6bb3d8c9ad 100644
--- a/app/components/Button.tsx
+++ b/app/components/Button.tsx
@@ -158,13 +158,14 @@ export type Props = ActionButtonProps & {
"data-on"?: string;
"data-event-category"?: string;
"data-event-action"?: string;
+ ref?: React.Ref;
};
-const Button = (
- props: Props & React.ComponentPropsWithoutRef,
- ref: React.Ref
-) => {
+function Button(
+ props: Props & React.ComponentPropsWithoutRef
+) {
const {
+ ref,
type,
children,
value,
@@ -200,10 +201,10 @@ const Button = (
);
-};
+}
const StyledDisclosureIcon = styled(DisclosureIcon)`
opacity: 0.8;
`;
-export default React.forwardRef(Button);
+export default Button;
diff --git a/app/components/ColorButton.tsx b/app/components/ColorButton.tsx
index 1c3b359a87..67b4f76d06 100644
--- a/app/components/ColorButton.tsx
+++ b/app/components/ColorButton.tsx
@@ -10,13 +10,17 @@ type Props = React.HTMLAttributes & {
active?: boolean;
/** The size of the button in pixels */
size?: number;
+ ref?: React.Ref;
};
-export const ColorButton = React.forwardRef(
- (
- { color, active = false, size = 24, ...rest }: Props,
- ref: React.Ref
- ) => (
+export function ColorButton({
+ color,
+ active = false,
+ size = 24,
+ ref,
+ ...rest
+}: Props) {
+ return (
- )
-);
+ );
+}
/** Highlight for the hovered or selected swatch, falls back for the gradient. */
const ring = css`2px solid var(--color, ${s("textTertiary")})`;
diff --git a/app/components/CommandBar/CommandBarItem.tsx b/app/components/CommandBar/CommandBarItem.tsx
index edb163fb2c..5af103303e 100644
--- a/app/components/CommandBar/CommandBarItem.tsx
+++ b/app/components/CommandBar/CommandBarItem.tsx
@@ -14,6 +14,7 @@ type Props = {
action: CommandBarActionImpl;
active: boolean;
currentRootActionId: string | null | undefined;
+ ref?: React.Ref;
};
const SEARCH_RESULT_REGEX = /]*>(.*?)<\/b>/gi;
@@ -24,10 +25,7 @@ function replaceResultMarks(tag: string) {
return tag.replace(/]*>(.*?)<\/b>/gi, "$1");
}
-function CommandBarItem(
- { action, active, currentRootActionId }: Props,
- ref: React.RefObject
-) {
+function CommandBarItem({ action, active, currentRootActionId, ref }: Props) {
const theme = useTheme();
const ancestors = React.useMemo(() => {
if (!currentRootActionId || !action.ancestors) {
@@ -168,4 +166,4 @@ const ForwardIcon = styled(BackIcon)`
flex-shrink: 0;
`;
-export default React.forwardRef(CommandBarItem);
+export default CommandBarItem;
diff --git a/app/components/CommandBar/useSearchIndex.ts b/app/components/CommandBar/useSearchIndex.ts
index 7ca8ec263e..d81900984c 100644
--- a/app/components/CommandBar/useSearchIndex.ts
+++ b/app/components/CommandBar/useSearchIndex.ts
@@ -90,7 +90,7 @@ export interface UseSearchIndex {
* @returns the current results and functions to feed or reset the index.
*/
export function useSearchIndex(query: string): UseSearchIndex {
- const indexRef = useRef();
+ const indexRef = useRef(undefined);
if (!indexRef.current) {
indexRef.current = new SearchIndex();
}
diff --git a/app/components/ContentEditable.tsx b/app/components/ContentEditable.tsx
index 20b3948e81..c3ad930c27 100644
--- a/app/components/ContentEditable.tsx
+++ b/app/components/ContentEditable.tsx
@@ -2,6 +2,7 @@ import isPrintableKeyEvent from "is-printable-key-event";
import * as React from "react";
import styled from "styled-components";
import { s } from "@shared/styles";
+import { TextHelper } from "@shared/utils/TextHelper";
import useOnScreen from "~/hooks/useOnScreen";
type Props = Omit, "ref" | "onChange"> & {
@@ -13,11 +14,13 @@ type Props = Omit, "ref" | "onChange"> & {
onBlur?: React.FocusEventHandler | undefined;
onInput?: React.FormEventHandler | undefined;
onKeyDown?: React.KeyboardEventHandler | undefined;
+ onCompositionEnd?: React.CompositionEventHandler | undefined;
placeholder?: string;
maxLength?: number;
autoFocus?: boolean;
children?: React.ReactNode;
value: string;
+ ref?: React.Ref;
};
export type RefHandle = {
@@ -31,29 +34,29 @@ export type RefHandle = {
* Defines a content editable component with the same interface as a native
* HTMLInputElement (or, as close as we can get).
*/
-const ContentEditable = React.forwardRef(function ContentEditable_(
- {
- disabled,
- onChange,
- onInput,
- onFocus,
- onBlur,
- onKeyDown,
- value,
- children,
- className,
- maxLength,
- autoFocus,
- placeholder,
- readOnly,
- dir,
- onClick,
- ...rest
- }: Props,
- ref: React.RefObject
-) {
+function ContentEditable({
+ disabled,
+ onChange,
+ onInput,
+ onFocus,
+ onBlur,
+ onKeyDown,
+ onCompositionEnd,
+ value,
+ children,
+ className,
+ maxLength,
+ autoFocus,
+ placeholder,
+ readOnly,
+ dir,
+ onClick,
+ ref,
+ ...rest
+}: Props) {
const contentRef = React.useRef(null);
const [innerValue, setInnerValue] = React.useState(value);
+ const [isEmpty, setIsEmpty] = React.useState(value.length === 0);
const lastValue = React.useRef(value);
React.useImperativeHandle(ref, () => ({
@@ -95,18 +98,33 @@ const ContentEditable = React.forwardRef(function ContentEditable_(
return;
}
- const text = event.currentTarget.textContent || "";
+ let text = event.currentTarget.textContent || "";
+ setIsEmpty(text.length === 0);
+ const overLimit =
+ !!maxLength && TextHelper.codePointLength(text) > maxLength;
if (
maxLength &&
event.nativeEvent instanceof KeyboardEvent &&
isPrintableKeyEvent(event.nativeEvent) &&
- text.length >= maxLength
+ TextHelper.codePointLength(text) >= maxLength
) {
event.preventDefault();
return;
}
+ // Paste, drop, IME and other non-keyboard input paths bypass the check
+ // above, so clamp whatever landed in the DOM. Editing the DOM would
+ // break an active IME session, so wait for composition end and do not
+ // publish the over-limit buffer in the meantime.
+ if (overLimit && maxLength) {
+ if (isComposing(event)) {
+ callback?.(event);
+ return;
+ }
+ text = truncateContent(event.currentTarget, maxLength);
+ }
+
if (text !== lastValue.current) {
lastValue.current = text;
onChange?.(text);
@@ -128,8 +146,17 @@ const ContentEditable = React.forwardRef(function ContentEditable_(
}, [autoFocus, disabled, isVisible, readOnly, contentRef]);
React.useEffect(() => {
- if (contentRef.current && value !== contentRef.current.textContent) {
- if (document.activeElement === contentRef.current) {
+ if (!contentRef.current) {
+ return;
+ }
+
+ const isFocused = document.activeElement === contentRef.current;
+ setIsEmpty(
+ isFocused ? !contentRef.current.textContent : value.length === 0
+ );
+
+ if (value !== contentRef.current.textContent) {
+ if (isFocused) {
// Don't reset content while the user is actively editing. Update
// lastValue so that the next input or blur event will push the
// current DOM text back to the model via onChange.
@@ -146,10 +173,21 @@ const ContentEditable = React.forwardRef(function ContentEditable_(
const handlePaste = React.useCallback(
(event: React.ClipboardEvent) => {
event.preventDefault();
- const text = event.clipboardData.getData("text/plain");
+ let text = event.clipboardData.getData("text/plain");
+
+ if (maxLength) {
+ const current = event.currentTarget.textContent || "";
+ const selected = window.getSelection()?.toString() || "";
+ const remaining =
+ maxLength -
+ (TextHelper.codePointLength(current) -
+ TextHelper.codePointLength(selected));
+ text = TextHelper.truncate(text, remaining);
+ }
+
window.document.execCommand("insertText", false, text);
},
- []
+ [maxLength]
);
const contentEditable = !disabled && !readOnly;
@@ -163,8 +201,10 @@ const ContentEditable = React.forwardRef(function ContentEditable_(
onFocus={wrappedEvent(onFocus)}
onBlur={wrappedEvent(onBlur)}
onKeyDown={wrappedEvent(onKeyDown)}
+ onCompositionEnd={wrappedEvent(onCompositionEnd)}
onPaste={handlePaste}
data-placeholder={placeholder}
+ data-empty={isEmpty}
suppressContentEditableWarning
role={contentEditable ? "textbox" : undefined}
{...rest}
@@ -173,7 +213,46 @@ const ContentEditable = React.forwardRef(function ContentEditable_(
);
-});
+}
+
+function isComposing(event: React.SyntheticEvent) {
+ const native = event.nativeEvent;
+ return (
+ (native instanceof InputEvent || native instanceof KeyboardEvent) &&
+ native.isComposing
+ );
+}
+
+/**
+ * Truncates the text content of an element to the given number of code points
+ * while keeping the caret at its current position where possible.
+ */
+function truncateContent(element: HTMLElement, maxLength: number): string {
+ const selection = window.getSelection();
+ const range = selection?.rangeCount ? selection.getRangeAt(0) : undefined;
+ let offset = Number.MAX_SAFE_INTEGER;
+
+ if (range && element.contains(range.startContainer)) {
+ const before = range.cloneRange();
+ before.selectNodeContents(element);
+ before.setEnd(range.startContainer, range.startOffset);
+ offset = before.toString().length;
+ }
+
+ const text = TextHelper.truncate(element.textContent || "", maxLength);
+ element.textContent = text;
+
+ const textNode = element.firstChild;
+ if (textNode && selection) {
+ const caret = document.createRange();
+ caret.setStart(textNode, Math.min(offset, text.length));
+ caret.collapse(true);
+ selection.removeAllRanges();
+ selection.addRange(caret);
+ }
+
+ return text;
+}
function placeCaret(element: HTMLElement, atStart: boolean) {
if (
@@ -198,12 +277,14 @@ const Content = styled.span`
cursor: text;
word-break: anywhere;
- &:empty {
+ /* Browsers can leave line breaks behind after all text is deleted. */
+ &[data-empty="true"] {
display: inline-block;
}
- &:empty::before {
+ &[data-empty="true"]::before {
display: inline-block;
+ float: inline-start;
color: ${s("placeholder")};
-webkit-text-fill-color: ${s("placeholder")};
content: attr(data-placeholder);
diff --git a/app/components/CopyToClipboard.ts b/app/components/CopyToClipboard.ts
index 5dc70b7cd4..92068f1cf1 100644
--- a/app/components/CopyToClipboard.ts
+++ b/app/components/CopyToClipboard.ts
@@ -3,15 +3,21 @@ import * as React from "react";
import { mergeRefs } from "react-merge-refs";
import env from "~/env";
-type Props = {
- text: string;
- children?: React.ReactElement;
- onClick?: React.MouseEventHandler;
- onCopy?: () => void;
+type ChildProps = {
+ onClick?: React.MouseEventHandler;
+ ref?: React.Ref;
};
-function CopyToClipboard(props: Props, ref: React.Ref) {
- const { text, onCopy, children, ...rest } = props;
+type Props = {
+ text: string;
+ children?: React.ReactElement;
+ onClick?: React.MouseEventHandler;
+ onCopy?: () => void;
+ ref?: React.Ref;
+};
+
+function CopyToClipboard(props: Props) {
+ const { text, onCopy, children, ref, ...rest } = props;
const onClick = React.useCallback(
(ev: React.MouseEvent) => {
@@ -45,12 +51,9 @@ function CopyToClipboard(props: Props, ref: React.Ref) {
return React.cloneElement(elem, {
...rest,
- ref:
- "ref" in elem
- ? mergeRefs([elem.ref as React.MutableRefObject, ref])
- : ref,
+ ref: elem.props.ref ? mergeRefs([elem.props.ref, ref]) : ref,
onClick,
});
}
-export default React.forwardRef(CopyToClipboard);
+export default CopyToClipboard;
diff --git a/app/components/DelayedMount.ts b/app/components/DelayedMount.ts
index 40a806a165..0fc403d6ba 100644
--- a/app/components/DelayedMount.ts
+++ b/app/components/DelayedMount.ts
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
type Props = {
delay?: number;
- children: JSX.Element;
+ children: React.JSX.Element;
};
export default function DelayedMount({ delay = 250, children }: Props) {
diff --git a/app/components/DeprecatedReason.tsx b/app/components/DeprecatedReason.tsx
new file mode 100644
index 0000000000..f90a96cfab
--- /dev/null
+++ b/app/components/DeprecatedReason.tsx
@@ -0,0 +1,93 @@
+import { observer } from "mobx-react";
+import { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { toast } from "sonner";
+import styled from "styled-components";
+import { DeprecationValidation } from "@shared/validations";
+import type Collection from "~/models/Collection";
+import type Document from "~/models/Document";
+import ContentEditable from "~/components/ContentEditable";
+import usePolicy from "~/hooks/usePolicy";
+
+interface Props {
+ model: Document | Collection;
+}
+
+/**
+ * Displays an editable reason for archiving or deleting a document or collection.
+ *
+ * @param props the model to describe.
+ * @returns the reason field, in read-only mode for readers.
+ */
+export const DeprecatedReason = observer(function DeprecatedReason({
+ model,
+}: Props) {
+ const { t } = useTranslation();
+ const can = usePolicy(model);
+ const readOnly = !can.updateDeprecatedReason;
+ const [draft, setDraft] = useState();
+ const value = draft ?? model.deprecatedReason ?? "";
+
+ const handleSave = async () => {
+ if (readOnly || model.isSaving || draft === undefined) {
+ return;
+ }
+
+ const deprecatedReason = draft.trim() || null;
+ if (deprecatedReason === model.deprecatedReason) {
+ setDraft(undefined);
+ return;
+ }
+
+ try {
+ await model.save({ deprecatedReason });
+ setDraft(undefined);
+ toast.success(t("Reason saved"));
+ } catch {
+ toast.error(t("The reason could not be saved. Please try again."));
+ }
+ };
+
+ if (readOnly && !model.deprecatedReason) {
+ return null;
+ }
+
+ return (
+ {
+ if (
+ event.key === "Enter" &&
+ !event.shiftKey &&
+ !event.nativeEvent.isComposing
+ ) {
+ event.preventDefault();
+ event.currentTarget.blur();
+ }
+ }}
+ />
+ );
+});
+
+const Input = styled(ContentEditable)`
+ margin-top: 4px;
+
+ > span {
+ display: block;
+ background: transparent;
+ color: inherit;
+ -webkit-text-fill-color: currentColor;
+ white-space: pre-wrap;
+
+ &[data-empty="true"] {
+ display: block;
+ }
+ }
+`;
diff --git a/app/components/DeprecationNotice.tsx b/app/components/DeprecationNotice.tsx
new file mode 100644
index 0000000000..16cec7baad
--- /dev/null
+++ b/app/components/DeprecationNotice.tsx
@@ -0,0 +1,15 @@
+import styled from "styled-components";
+import { s } from "@shared/styles";
+import Notice from "./Notice";
+
+/** A deprecation notice with a focus border around its editable reason. */
+export const DeprecationNotice = styled(Notice)`
+ &:has([contenteditable="true"]:focus) {
+ outline: 1px solid ${s("inputBorderFocused")};
+ }
+
+ > span > span {
+ flex: 1;
+ min-width: 0;
+ }
+`;
diff --git a/app/components/DesktopEventHandler.tsx b/app/components/DesktopEventHandler.tsx
index 28ca23249c..0243f014b5 100644
--- a/app/components/DesktopEventHandler.tsx
+++ b/app/components/DesktopEventHandler.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { toast } from "sonner";
import KeyboardShortcuts from "~/scenes/KeyboardShortcuts";
+import { showDownloadToast } from "~/components/DownloadToast";
import { useDesktopTitlebar } from "~/hooks/useDesktopTitlebar";
import useStores from "~/hooks/useStores";
import Desktop from "~/utils/Desktop";
@@ -41,6 +42,8 @@ export default function DesktopEventHandler() {
});
});
+ Desktop.bridge?.onDownloadComplete?.(showDownloadToast);
+
Desktop.bridge?.focus(() => {
window.document.body.classList.remove("backgrounded");
});
diff --git a/app/components/DocumentArchiveDialog.tsx b/app/components/DocumentArchiveDialog.tsx
new file mode 100644
index 0000000000..a6d95d7b2f
--- /dev/null
+++ b/app/components/DocumentArchiveDialog.tsx
@@ -0,0 +1,53 @@
+import { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { DeprecationValidation } from "@shared/validations";
+import ConfirmationDialog from "~/components/ConfirmationDialog";
+import Flex from "~/components/Flex";
+import Input from "~/components/Input";
+
+interface Props {
+ count: number;
+ onSubmit: (reason?: string) => Promise;
+}
+
+/**
+ * Confirms document archival with an optional reason.
+ *
+ * @param props the document count and archive callback.
+ * @returns the archive confirmation form.
+ */
+export function DocumentArchiveDialog({ count, onSubmit }: Props) {
+ const { t } = useTranslation();
+ const [reason, setReason] = useState("");
+
+ const handleSubmit = () => onSubmit(reason.trim() || undefined);
+
+ return (
+
+
+
+ {count === 1
+ ? t(
+ "Archiving this document will remove it from the collection and search results."
+ )
+ : t(
+ "Archiving these documents will remove them from their collections and search results."
+ )}
+