mirror of
https://github.com/outline/outline.git
synced 2026-11-29 16:40:27 +03:00
Merge branch 'main' into tommoor/personal-documents
Resolves conflicts with the document deprecation feature: the update route destructuring gains both personalOwnerId and the deprecatedReason handling, the MCP test file keeps both sides' new suites, and the reparent drop hook adopts useDropRef while keeping membership drag types. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
342 files changed
+8143
-3450
No files matched your search
@@ -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
|
||||
+21
-24
@@ -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
|
||||
|
||||
@@ -70,6 +70,12 @@
|
||||
"valid-typeof": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["**/*.{ts,tsx}"],
|
||||
"rules": {
|
||||
"no-redeclare": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["**/*.{js,jsx,ts,tsx}"],
|
||||
"rules": {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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: <MarkdownIcon />,
|
||||
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: <CodeIcon />,
|
||||
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: <ArchiveIcon />,
|
||||
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: <PDFIcon />,
|
||||
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: <PrintIcon />,
|
||||
iconInContextMenu: false,
|
||||
visible: ({ activeDocumentId }) => !!(activeDocumentId && window.print),
|
||||
@@ -1473,10 +1488,11 @@ export const archiveDocument = createAction({
|
||||
})
|
||||
),
|
||||
content: (
|
||||
<ConfirmationDialog
|
||||
onSubmit={async () => {
|
||||
<DocumentArchiveDialog
|
||||
count={documents.length}
|
||||
onSubmit={async (reason) => {
|
||||
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."
|
||||
)}
|
||||
</ConfirmationDialog>
|
||||
/>
|
||||
),
|
||||
});
|
||||
},
|
||||
|
||||
+16
-19
@@ -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<React.ReactChild>(action.tooltip, context),
|
||||
tooltip: resolve<React.ReactNode>(action.tooltip, context),
|
||||
selected: resolve<boolean>(action.selected, context),
|
||||
dangerous: action.dangerous,
|
||||
shortcut,
|
||||
@@ -353,6 +336,20 @@ export async function performAction(
|
||||
? () => history.push(resolve<LocationDescriptor>(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) {
|
||||
|
||||
@@ -22,68 +22,67 @@ export type Props = React.HTMLAttributes<HTMLButtonElement> & {
|
||||
/**
|
||||
* Button that can be used to trigger an action definition.
|
||||
*/
|
||||
const ActionButton = React.forwardRef<HTMLButtonElement, Props>(
|
||||
function ActionButton_(
|
||||
{ action, tooltip, hideOnActionDisabled, ...rest }: Props,
|
||||
ref: React.Ref<HTMLButtonElement>
|
||||
) {
|
||||
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<HTMLButtonElement> }) {
|
||||
const actionContext = useActionContext({
|
||||
isButton: true,
|
||||
});
|
||||
const isMounted = useIsMounted();
|
||||
const [executing, setExecuting] = React.useState(false);
|
||||
|
||||
if (!actionContext || !action) {
|
||||
return <button {...rest} ref={ref} />;
|
||||
}
|
||||
|
||||
const actionIsDisabled =
|
||||
action.visible && !resolve<boolean>(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 = (
|
||||
<button
|
||||
{...rest}
|
||||
aria-label={typeof label === "string" ? label : undefined}
|
||||
disabled={disabled || executing}
|
||||
ref={ref}
|
||||
onClick={
|
||||
actionContext
|
||||
? (ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const response = performAction(action, actionContext);
|
||||
if (response?.finally) {
|
||||
setExecuting(true);
|
||||
void response.finally(
|
||||
() => isMounted() && setExecuting(false)
|
||||
);
|
||||
}
|
||||
}
|
||||
: rest.onClick
|
||||
}
|
||||
>
|
||||
{rest.children ?? label}
|
||||
</button>
|
||||
);
|
||||
|
||||
if (tooltip) {
|
||||
return <Tooltip {...tooltip}>{button}</Tooltip>;
|
||||
}
|
||||
|
||||
return button;
|
||||
if (!actionContext || !action) {
|
||||
return <button {...rest} ref={ref} />;
|
||||
}
|
||||
);
|
||||
|
||||
const actionIsDisabled =
|
||||
action.visible && !resolve<boolean>(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 = (
|
||||
<button
|
||||
{...rest}
|
||||
aria-label={typeof label === "string" ? label : undefined}
|
||||
disabled={disabled || executing}
|
||||
ref={ref}
|
||||
onClick={
|
||||
actionContext
|
||||
? (ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const response = performAction(action, actionContext);
|
||||
if (response?.finally) {
|
||||
setExecuting(true);
|
||||
void response.finally(() => isMounted() && setExecuting(false));
|
||||
}
|
||||
}
|
||||
: rest.onClick
|
||||
}
|
||||
>
|
||||
{rest.children ?? label}
|
||||
</button>
|
||||
);
|
||||
|
||||
if (tooltip) {
|
||||
return <Tooltip {...tooltip}>{button}</Tooltip>;
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
export default observer(ActionButton);
|
||||
@@ -6,12 +6,16 @@ type Props = Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
|
||||
children: () => React.ReactNode;
|
||||
onEscape?: (ev: React.KeyboardEvent<HTMLDivElement>) => void;
|
||||
items: unknown[];
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
function ArrowKeyNavigation(
|
||||
{ children, onEscape, items, ...rest }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
function ArrowKeyNavigation({
|
||||
children,
|
||||
onEscape,
|
||||
items,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
const handleKeyDown = React.useCallback(
|
||||
(ev: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
if (onEscape) {
|
||||
@@ -48,4 +52,4 @@ function ArrowKeyNavigation(
|
||||
);
|
||||
}
|
||||
|
||||
export default observer(React.forwardRef(ArrowKeyNavigation));
|
||||
export default observer(ArrowKeyNavigation);
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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<HTMLDivElement>;
|
||||
} & Omit<
|
||||
React.ComponentPropsWithoutRef<"div">,
|
||||
"onClick" | "className" | "style"
|
||||
>;
|
||||
|
||||
const Avatar = React.forwardRef(function Avatar_(
|
||||
props: AvatarProps,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
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;
|
||||
|
||||
@@ -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<HTMLDivElement>
|
||||
) {
|
||||
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_(
|
||||
<Avatar ref={ref} {...props} />
|
||||
</UserHoverCard>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export default observer(AvatarWithHoverCard);
|
||||
@@ -20,12 +20,16 @@ type Props = React.PropsWithChildren<{
|
||||
actions: InternalLinkAction[];
|
||||
max?: number;
|
||||
highlightFirstItem?: boolean;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
}>;
|
||||
|
||||
function Breadcrumb(
|
||||
{ actions, highlightFirstItem, children, max = 2 }: Props,
|
||||
ref: React.RefObject<HTMLDivElement> | 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<HTMLDivElement, Props>(Breadcrumb));
|
||||
export default observer(Breadcrumb);
|
||||
@@ -158,13 +158,14 @@ export type Props<T> = ActionButtonProps & {
|
||||
"data-on"?: string;
|
||||
"data-event-category"?: string;
|
||||
"data-event-action"?: string;
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
const Button = <T extends React.ElementType = "button">(
|
||||
props: Props<T> & React.ComponentPropsWithoutRef<T>,
|
||||
ref: React.Ref<HTMLButtonElement>
|
||||
) => {
|
||||
function Button<T extends React.ElementType = "button">(
|
||||
props: Props<T> & React.ComponentPropsWithoutRef<T>
|
||||
) {
|
||||
const {
|
||||
ref,
|
||||
type,
|
||||
children,
|
||||
value,
|
||||
@@ -200,10 +201,10 @@ const Button = <T extends React.ElementType = "button">(
|
||||
</Inner>
|
||||
</RealButton>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const StyledDisclosureIcon = styled(DisclosureIcon)`
|
||||
opacity: 0.8;
|
||||
`;
|
||||
|
||||
export default React.forwardRef(Button);
|
||||
export default Button;
|
||||
@@ -10,13 +10,17 @@ type Props = React.HTMLAttributes<HTMLButtonElement> & {
|
||||
active?: boolean;
|
||||
/** The size of the button in pixels */
|
||||
size?: number;
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
export const ColorButton = React.forwardRef(
|
||||
(
|
||||
{ color, active = false, size = 24, ...rest }: Props,
|
||||
ref: React.Ref<HTMLButtonElement>
|
||||
) => (
|
||||
export function ColorButton({
|
||||
color,
|
||||
active = false,
|
||||
size = 24,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
return (
|
||||
<ColorButtonInternal
|
||||
$active={active}
|
||||
$size={size}
|
||||
@@ -26,8 +30,8 @@ export const ColorButton = React.forwardRef(
|
||||
>
|
||||
<Selected />
|
||||
</ColorButtonInternal>
|
||||
)
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/** Highlight for the hovered or selected swatch, falls back for the gradient. */
|
||||
const ring = css`2px solid var(--color, ${s("textTertiary")})`;
|
||||
|
||||
@@ -14,6 +14,7 @@ type Props = {
|
||||
action: CommandBarActionImpl;
|
||||
active: boolean;
|
||||
currentRootActionId: string | null | undefined;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const SEARCH_RESULT_REGEX = /<b\b[^>]*>(.*?)<\/b>/gi;
|
||||
@@ -24,10 +25,7 @@ function replaceResultMarks(tag: string) {
|
||||
return tag.replace(/<b\b[^>]*>(.*?)<\/b>/gi, "$1");
|
||||
}
|
||||
|
||||
function CommandBarItem(
|
||||
{ action, active, currentRootActionId }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
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<HTMLDivElement, Props>(CommandBarItem);
|
||||
export default CommandBarItem;
|
||||
@@ -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<SearchIndex>();
|
||||
const indexRef = useRef<SearchIndex | undefined>(undefined);
|
||||
if (!indexRef.current) {
|
||||
indexRef.current = new SearchIndex();
|
||||
}
|
||||
|
||||
@@ -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<React.HTMLAttributes<HTMLSpanElement>, "ref" | "onChange"> & {
|
||||
@@ -13,11 +14,13 @@ type Props = Omit<React.HTMLAttributes<HTMLSpanElement>, "ref" | "onChange"> & {
|
||||
onBlur?: React.FocusEventHandler<HTMLSpanElement> | undefined;
|
||||
onInput?: React.FormEventHandler<HTMLSpanElement> | undefined;
|
||||
onKeyDown?: React.KeyboardEventHandler<HTMLSpanElement> | undefined;
|
||||
onCompositionEnd?: React.CompositionEventHandler<HTMLSpanElement> | undefined;
|
||||
placeholder?: string;
|
||||
maxLength?: number;
|
||||
autoFocus?: boolean;
|
||||
children?: React.ReactNode;
|
||||
value: string;
|
||||
ref?: React.Ref<RefHandle>;
|
||||
};
|
||||
|
||||
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<RefHandle>
|
||||
) {
|
||||
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<HTMLSpanElement>(null);
|
||||
const [innerValue, setInnerValue] = React.useState<string>(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<HTMLSpanElement>) => {
|
||||
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_(
|
||||
</Content>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function isComposing(event: React.SyntheticEvent<HTMLSpanElement>) {
|
||||
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);
|
||||
|
||||
@@ -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<HTMLButtonElement>;
|
||||
onCopy?: () => void;
|
||||
type ChildProps = {
|
||||
onClick?: React.MouseEventHandler<HTMLElement>;
|
||||
ref?: React.Ref<HTMLElement>;
|
||||
};
|
||||
|
||||
function CopyToClipboard(props: Props, ref: React.Ref<HTMLElement>) {
|
||||
const { text, onCopy, children, ...rest } = props;
|
||||
type Props = {
|
||||
text: string;
|
||||
children?: React.ReactElement<ChildProps>;
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
onCopy?: () => void;
|
||||
ref?: React.Ref<HTMLElement>;
|
||||
};
|
||||
|
||||
function CopyToClipboard(props: Props) {
|
||||
const { text, onCopy, children, ref, ...rest } = props;
|
||||
|
||||
const onClick = React.useCallback(
|
||||
(ev: React.MouseEvent<HTMLElement>) => {
|
||||
@@ -45,12 +51,9 @@ function CopyToClipboard(props: Props, ref: React.Ref<HTMLElement>) {
|
||||
|
||||
return React.cloneElement(elem, {
|
||||
...rest,
|
||||
ref:
|
||||
"ref" in elem
|
||||
? mergeRefs([elem.ref as React.MutableRefObject<HTMLElement>, ref])
|
||||
: ref,
|
||||
ref: elem.props.ref ? mergeRefs([elem.props.ref, ref]) : ref,
|
||||
onClick,
|
||||
});
|
||||
}
|
||||
|
||||
export default React.forwardRef(CopyToClipboard);
|
||||
export default CopyToClipboard;
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<string>();
|
||||
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 (
|
||||
<Input
|
||||
aria-label={t("Reason for archiving or deleting")}
|
||||
placeholder={readOnly ? undefined : `${t("Add a reason")}…`}
|
||||
value={readOnly ? (model.deprecatedReason ?? "") : value}
|
||||
readOnly={readOnly}
|
||||
maxLength={DeprecationValidation.maxReasonLength}
|
||||
disabled={model.isSaving}
|
||||
onChange={setDraft}
|
||||
onBlur={handleSave}
|
||||
onKeyDown={(event) => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -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;
|
||||
}
|
||||
`;
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
@@ -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<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
<ConfirmationDialog
|
||||
onSubmit={handleSubmit}
|
||||
submitText={t("Archive")}
|
||||
savingText={`${t("Archiving")}…`}
|
||||
>
|
||||
<Flex column gap={12}>
|
||||
<div>
|
||||
{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."
|
||||
)}
|
||||
</div>
|
||||
<Input
|
||||
name="reason"
|
||||
label={t("Reason (optional)")}
|
||||
placeholder={`${t("Add a reason")}…`}
|
||||
value={reason}
|
||||
onChange={(event) => setReason(event.currentTarget.value)}
|
||||
maxLength={DeprecationValidation.maxReasonLength}
|
||||
margin={0}
|
||||
/>
|
||||
</Flex>
|
||||
</ConfirmationDialog>
|
||||
);
|
||||
}
|
||||
@@ -91,12 +91,16 @@ type Props = {
|
||||
* ancestors are shown. If less than or equal to 0, no items are shown.
|
||||
*/
|
||||
maxDepth?: number;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
function DocumentBreadcrumb(
|
||||
{ document, children, onlyText, maxDepth }: Props,
|
||||
ref: React.RefObject<HTMLDivElement> | null
|
||||
) {
|
||||
function DocumentBreadcrumb({
|
||||
document,
|
||||
children,
|
||||
onlyText,
|
||||
maxDepth,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { collections } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const sidebarContext = useLocationSidebarContext();
|
||||
@@ -362,4 +366,4 @@ const SmallSlash = styled(GoToIcon)`
|
||||
opacity: 0.5;
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(DocumentBreadcrumb));
|
||||
export default observer(DocumentBreadcrumb);
|
||||
@@ -8,13 +8,19 @@ import type { TextStats } from "~/hooks/useTextStats";
|
||||
import { getTextStats } from "~/hooks/useTextStats";
|
||||
import type Document from "~/models/Document";
|
||||
import type { Editor } from "~/editor";
|
||||
import type { ConnectionStatus } from "~/utils/multiplayer/CollaborationProvider";
|
||||
|
||||
class DocumentContext {
|
||||
/** The current document */
|
||||
document?: Document;
|
||||
|
||||
/** The editor instance for this document */
|
||||
editor?: Editor;
|
||||
@observable.ref
|
||||
editor: Editor | undefined = undefined;
|
||||
|
||||
/** The total number of changes in the currently viewed revision diff */
|
||||
@observable
|
||||
totalChanges: number = 0;
|
||||
|
||||
/** The ID of the currently focused comment, or null if no comment is focused */
|
||||
@observable
|
||||
@@ -28,6 +34,22 @@ class DocumentContext {
|
||||
@observable
|
||||
headings: Heading[] = [];
|
||||
|
||||
/** The connection status of the collaboration provider */
|
||||
@observable
|
||||
multiplayerStatus: ConnectionStatus | undefined = undefined;
|
||||
|
||||
/** The close code of the collaboration connection, when it was closed with an error */
|
||||
@observable
|
||||
multiplayerErrorCode?: number = undefined;
|
||||
|
||||
/** Whether there are local edits the collaboration server has not confirmed */
|
||||
@observable
|
||||
hasUnsyncedChanges = false;
|
||||
|
||||
/** Whether edits are also stored in the browser, so they survive a reload */
|
||||
@observable
|
||||
hasLocalPersistence = true;
|
||||
|
||||
constructor() {
|
||||
makeObservable(this);
|
||||
}
|
||||
@@ -67,11 +89,31 @@ class DocumentContext {
|
||||
this.isEditorInitialized = initialized;
|
||||
};
|
||||
|
||||
@action
|
||||
setTotalChanges = (totalChanges: number) => {
|
||||
this.totalChanges = totalChanges;
|
||||
};
|
||||
|
||||
@action
|
||||
setFocusedCommentId = (commentId: string | null) => {
|
||||
this.focusedCommentId = commentId;
|
||||
};
|
||||
|
||||
@action
|
||||
setMultiplayerStatus = (status: ConnectionStatus, errorCode?: number) => {
|
||||
this.multiplayerStatus = status;
|
||||
this.multiplayerErrorCode = errorCode;
|
||||
};
|
||||
|
||||
@action
|
||||
setMultiplayerSyncState = (
|
||||
hasUnsyncedChanges: boolean,
|
||||
hasLocalPersistence: boolean
|
||||
) => {
|
||||
this.hasUnsyncedChanges = hasUnsyncedChanges;
|
||||
this.hasLocalPersistence = hasLocalPersistence;
|
||||
};
|
||||
|
||||
@action
|
||||
updateState = () => {
|
||||
this.editorDoc = this.editor?.view.state.doc;
|
||||
|
||||
@@ -45,13 +45,13 @@ type Props = {
|
||||
const VERTICAL_PADDING = 6;
|
||||
const HORIZONTAL_PADDING = 24;
|
||||
|
||||
const innerElementType = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(function innerElementType(
|
||||
{ style, ...rest }: React.HTMLAttributes<HTMLDivElement>,
|
||||
ref
|
||||
) {
|
||||
function innerElementType({
|
||||
style,
|
||||
ref,
|
||||
...rest
|
||||
}: React.HTMLAttributes<HTMLDivElement> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
@@ -62,7 +62,7 @@ const innerElementType = React.forwardRef<
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function DocumentExplorer({
|
||||
onSubmit,
|
||||
|
||||
@@ -33,25 +33,25 @@ type Props = {
|
||||
onClick: (ev: React.MouseEvent) => void;
|
||||
/** Fired when the node is double-clicked to submit the current selection. */
|
||||
onDoubleClick: (ev: React.MouseEvent) => void;
|
||||
/** Ref to the node element. */
|
||||
ref?: React.Ref<HTMLSpanElement>;
|
||||
};
|
||||
|
||||
function DocumentExplorerNode(
|
||||
{
|
||||
selected,
|
||||
active,
|
||||
style,
|
||||
expanded,
|
||||
icon,
|
||||
title,
|
||||
depth,
|
||||
hasChildren,
|
||||
onDisclosureClick,
|
||||
onPointerMove,
|
||||
onClick,
|
||||
onDoubleClick,
|
||||
}: Props,
|
||||
ref: React.RefObject<HTMLSpanElement>
|
||||
) {
|
||||
function DocumentExplorerNode({
|
||||
selected,
|
||||
active,
|
||||
style,
|
||||
expanded,
|
||||
icon,
|
||||
title,
|
||||
depth,
|
||||
hasChildren,
|
||||
onDisclosureClick,
|
||||
onPointerMove,
|
||||
onClick,
|
||||
onDoubleClick,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const DISCLOSURE = 24;
|
||||
const width = (depth + 2) * DISCLOSURE;
|
||||
@@ -148,4 +148,4 @@ export const Node = styled.span<{
|
||||
`}
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(DocumentExplorerNode));
|
||||
export default observer(DocumentExplorerNode);
|
||||
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
useFocusEffect,
|
||||
useRovingTabIndex,
|
||||
} from "@getoutline/react-roving-tabindex";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -35,6 +31,7 @@ import { ActionContextProvider } from "~/hooks/useActionContext";
|
||||
import { useDocumentMenuAction } from "~/hooks/useDocumentMenuAction";
|
||||
import { ContextMenu } from "./Menu/ContextMenu";
|
||||
import { useDocumentActiveModels } from "~/hooks/useDocumentActiveModels";
|
||||
import { useRovingTabIndex } from "~/hooks/useRovingTabIndex";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
@@ -44,6 +41,7 @@ type Props = {
|
||||
showCollection?: boolean;
|
||||
showPublished?: boolean;
|
||||
showDraft?: boolean;
|
||||
ref?: React.RefObject<HTMLAnchorElement | null>;
|
||||
};
|
||||
|
||||
const SEARCH_RESULT_REGEX = /<b\b[^>]*>(.*?)<\/b>/gi;
|
||||
@@ -53,10 +51,7 @@ function replaceResultMarks(tag: string) {
|
||||
return tag.replace(new RegExp(SEARCH_RESULT_REGEX.source), "$1");
|
||||
}
|
||||
|
||||
function DocumentListItem(
|
||||
props: Props,
|
||||
ref: React.RefObject<HTMLAnchorElement>
|
||||
) {
|
||||
function DocumentListItem(props: Props) {
|
||||
const { t } = useTranslation();
|
||||
const user = useCurrentUser();
|
||||
const theme = useTheme();
|
||||
@@ -66,14 +61,13 @@ function DocumentListItem(
|
||||
const selection = useModelSelection();
|
||||
const iconRef = React.useRef<HTMLDivElement>(null);
|
||||
|
||||
let itemRef: React.Ref<HTMLAnchorElement> =
|
||||
let itemRef: React.RefObject<HTMLAnchorElement | null> =
|
||||
React.useRef<HTMLAnchorElement>(null);
|
||||
if (ref) {
|
||||
itemRef = ref;
|
||||
if (props.ref) {
|
||||
itemRef = props.ref;
|
||||
}
|
||||
|
||||
const { focused, ...rovingTabIndex } = useRovingTabIndex(itemRef, false);
|
||||
useFocusEffect(focused, itemRef);
|
||||
|
||||
const {
|
||||
document,
|
||||
@@ -83,6 +77,7 @@ function DocumentListItem(
|
||||
showDraft = true,
|
||||
highlight,
|
||||
context,
|
||||
ref: _ref,
|
||||
...rest
|
||||
} = props;
|
||||
const queryIsInTitle =
|
||||
@@ -445,4 +440,4 @@ const ResultContext = styled(Highlight)`
|
||||
overflow: hidden;
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(DocumentListItem));
|
||||
export default observer(DocumentListItem);
|
||||
@@ -0,0 +1,71 @@
|
||||
import { t } from "i18next";
|
||||
import { useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import Button from "~/components/Button";
|
||||
import Flex from "~/components/Flex";
|
||||
import Desktop from "~/utils/Desktop";
|
||||
|
||||
type DownloadedFile = {
|
||||
/** The user facing name of the downloaded file. */
|
||||
fileName: string;
|
||||
/** The absolute path the file was saved to. */
|
||||
filePath: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays a toast notifying that a file finished downloading, with the file
|
||||
* name and actions to open the file or reveal it in the file manager. Desktop
|
||||
* app only.
|
||||
*
|
||||
* @param file the name and path of the downloaded file.
|
||||
*/
|
||||
export function showDownloadToast(file: DownloadedFile) {
|
||||
const toastId = `download-${file.filePath}`;
|
||||
|
||||
toast.message(t("Download complete"), {
|
||||
id: toastId,
|
||||
description: <DownloadToastDescription file={file} toastId={toastId} />,
|
||||
});
|
||||
}
|
||||
|
||||
function DownloadToastDescription({
|
||||
file,
|
||||
toastId,
|
||||
}: {
|
||||
file: DownloadedFile;
|
||||
toastId: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleOpen = useCallback(() => {
|
||||
toast.dismiss(toastId);
|
||||
void Desktop.bridge?.openDownload?.(file.filePath);
|
||||
}, [file.filePath, toastId]);
|
||||
|
||||
const handleShowInFolder = useCallback(() => {
|
||||
toast.dismiss(toastId);
|
||||
void Desktop.bridge?.showDownloadInFolder?.(file.filePath);
|
||||
}, [file.filePath, toastId]);
|
||||
|
||||
// The name given to the file manager differs by operating system.
|
||||
const showInFolderLabel = Desktop.isMacApp()
|
||||
? t("Show in Finder")
|
||||
: Desktop.isWindowsApp()
|
||||
? t("Show in Explorer")
|
||||
: t("Show in folder");
|
||||
|
||||
return (
|
||||
<Flex column gap={8}>
|
||||
{file.fileName}
|
||||
<Flex gap={4}>
|
||||
<Button onClick={handleOpen} neutral>
|
||||
{t("Open")}
|
||||
</Button>
|
||||
<Button onClick={handleShowInFolder} neutral>
|
||||
{showInFolderLabel}
|
||||
</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@@ -20,6 +20,7 @@ type Props = Omit<React.InputHTMLAttributes<HTMLInputElement>, "onSubmit"> & {
|
||||
maxLength?: number;
|
||||
/** The default editing state. */
|
||||
isEditing?: boolean;
|
||||
ref?: React.Ref<RefHandle>;
|
||||
};
|
||||
|
||||
export type RefHandle = {
|
||||
@@ -27,10 +28,15 @@ export type RefHandle = {
|
||||
setIsEditing: (isEditing: boolean) => void;
|
||||
};
|
||||
|
||||
function EditableTitle(
|
||||
{ title, onSubmit, canUpdate, onEditing, onCancel, ...rest }: Props,
|
||||
ref: React.RefObject<RefHandle>
|
||||
) {
|
||||
function EditableTitle({
|
||||
title,
|
||||
onSubmit,
|
||||
canUpdate,
|
||||
onEditing,
|
||||
onCancel,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
const [isEditing, setIsEditing] = React.useState(rest.isEditing || false);
|
||||
const [originalValue, setOriginalValue] = React.useState(title);
|
||||
const [value, setValue] = React.useState(title);
|
||||
@@ -190,4 +196,4 @@ const Input = styled.input`
|
||||
}
|
||||
`;
|
||||
|
||||
export default React.forwardRef(EditableTitle);
|
||||
export default EditableTitle;
|
||||
@@ -32,7 +32,7 @@ export type Props = Optional<
|
||||
editorStyle?: React.CSSProperties;
|
||||
};
|
||||
|
||||
function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
function Editor({ ref, ...props }: Props & { ref?: React.Ref<SharedEditor> }) {
|
||||
const {
|
||||
id,
|
||||
onChange,
|
||||
@@ -45,9 +45,9 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
const { shareId } = useShare();
|
||||
const { t } = useTranslation();
|
||||
const embeds = useEmbeds(!shareId);
|
||||
const localRef = React.useRef<SharedEditor>();
|
||||
const localRef = React.useRef<SharedEditor | undefined>(undefined);
|
||||
const preferences = useCurrentUser({ rejectOnEmpty: false })?.preferences;
|
||||
const previousCommentIds = React.useRef<string[]>();
|
||||
const previousCommentIds = React.useRef<string[] | undefined>(undefined);
|
||||
|
||||
// Upload progress tracking for delayed toast
|
||||
const progressMap = React.useMemo(() => new Map<string, number>(), []);
|
||||
@@ -265,4 +265,4 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
);
|
||||
}
|
||||
|
||||
export default observer(React.forwardRef(Editor));
|
||||
export default observer(Editor);
|
||||
@@ -12,7 +12,7 @@ const Fade = styled.span<{ timing?: number | string }>`
|
||||
`;
|
||||
|
||||
type Props = {
|
||||
children?: JSX.Element | null;
|
||||
children?: React.JSX.Element | null;
|
||||
/** If true, children will be animated. */
|
||||
animate: boolean;
|
||||
};
|
||||
|
||||
@@ -35,12 +35,10 @@ type Props = {
|
||||
| React.ReactNode;
|
||||
hasSidebar?: boolean;
|
||||
className?: string;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
function Header(
|
||||
{ left, title, actions, hasSidebar, className }: Props,
|
||||
ref: React.RefObject<HTMLDivElement> | null
|
||||
) {
|
||||
function Header({ left, title, actions, hasSidebar, className, ref }: Props) {
|
||||
const { ui } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const { pane, isSplitView } = useSplitView();
|
||||
@@ -251,4 +249,4 @@ const CloseSplitPaneButton = styled(Button)`
|
||||
pointer-events: auto;
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(Header));
|
||||
export default observer(Header);
|
||||
@@ -44,7 +44,9 @@ const HoverPreviewDesktop = observer(
|
||||
({ element, unfurlId, dataLoading, onClose }: Props) => {
|
||||
const { unfurls } = useStores();
|
||||
const [isVisible, setVisible] = React.useState(false);
|
||||
const timerClose = React.useRef<ReturnType<typeof setTimeout>>();
|
||||
const timerClose = React.useRef<ReturnType<typeof setTimeout> | undefined>(
|
||||
undefined
|
||||
);
|
||||
const cardRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const { cardLeft, cardTop, pointerLeft, pointerTop, pointerDir } =
|
||||
useHoverPosition({
|
||||
@@ -248,7 +250,7 @@ function useHoverPosition({
|
||||
element,
|
||||
isVisible,
|
||||
}: {
|
||||
cardRef: React.RefObject<HTMLDivElement>;
|
||||
cardRef: React.RefObject<HTMLDivElement | null>;
|
||||
element: HTMLElement | null;
|
||||
isVisible: boolean;
|
||||
}) {
|
||||
|
||||
@@ -13,37 +13,56 @@ import {
|
||||
Description,
|
||||
} from "./Components";
|
||||
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Document], "type">;
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Document], "type"> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
function HoverPreviewDocument({
|
||||
url,
|
||||
id,
|
||||
title,
|
||||
summary,
|
||||
lastActivityByViewer,
|
||||
ref,
|
||||
}: Props) {
|
||||
const parsedUrl = new URL(url, window.location.href);
|
||||
const content = (
|
||||
<Card ref={ref}>
|
||||
<CardContent>
|
||||
<ErrorBoundary showTitle={false} reloadOnChunkMissing={false}>
|
||||
<Flex column gap={2}>
|
||||
<Title>{title}</Title>
|
||||
{lastActivityByViewer && <Info>{lastActivityByViewer}</Info>}
|
||||
<Description as="div">
|
||||
<React.Suspense fallback={<div />}>
|
||||
<Editor
|
||||
key={id}
|
||||
extensions={richExtensions}
|
||||
defaultValue={summary}
|
||||
embedsDisabled
|
||||
readOnly
|
||||
/>
|
||||
</React.Suspense>
|
||||
</Description>
|
||||
</Flex>
|
||||
</ErrorBoundary>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
if (parsedUrl.origin !== window.location.origin) {
|
||||
return (
|
||||
<Preview as="a" href={url}>
|
||||
{content}
|
||||
</Preview>
|
||||
);
|
||||
}
|
||||
|
||||
const HoverPreviewDocument = React.forwardRef(function HoverPreviewDocument_(
|
||||
{ url, id, title, summary, lastActivityByViewer }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
return (
|
||||
<Preview to={url}>
|
||||
<Card ref={ref}>
|
||||
<CardContent>
|
||||
<ErrorBoundary showTitle={false} reloadOnChunkMissing={false}>
|
||||
<Flex column gap={2}>
|
||||
<Title>{title}</Title>
|
||||
{lastActivityByViewer && <Info>{lastActivityByViewer}</Info>}
|
||||
<Description as="div">
|
||||
<React.Suspense fallback={<div />}>
|
||||
<Editor
|
||||
key={id}
|
||||
extensions={richExtensions}
|
||||
defaultValue={summary}
|
||||
embedsDisabled
|
||||
readOnly
|
||||
/>
|
||||
</React.Suspense>
|
||||
</Description>
|
||||
</Flex>
|
||||
</ErrorBoundary>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Preview to={`${parsedUrl.pathname}${parsedUrl.search}${parsedUrl.hash}`}>
|
||||
{content}
|
||||
</Preview>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export default HoverPreviewDocument;
|
||||
@@ -15,12 +15,17 @@ import {
|
||||
} from "./Components";
|
||||
import ErrorBoundary from "../ErrorBoundary";
|
||||
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Group], "type">;
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Group], "type"> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const HoverPreviewGroup = React.forwardRef(function HoverPreviewGroup_(
|
||||
{ name, description, memberCount, users }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
function HoverPreviewGroup({
|
||||
name,
|
||||
description,
|
||||
memberCount,
|
||||
users,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
@@ -65,6 +70,6 @@ const HoverPreviewGroup = React.forwardRef(function HoverPreviewGroup_(
|
||||
</Card>
|
||||
</Preview>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export default HoverPreviewGroup;
|
||||
@@ -21,12 +21,21 @@ import {
|
||||
Info,
|
||||
} from "./Components";
|
||||
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Issue], "type">;
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Issue], "type"> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const HoverPreviewIssue = React.forwardRef(function HoverPreviewIssue_(
|
||||
{ url, id, title, description, author, labels, state, createdAt }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
function HoverPreviewIssue({
|
||||
url,
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
author,
|
||||
labels,
|
||||
state,
|
||||
createdAt,
|
||||
ref,
|
||||
}: Props) {
|
||||
const authorName = author.name;
|
||||
const urlObj = new URL(url);
|
||||
const service =
|
||||
@@ -88,7 +97,7 @@ const HoverPreviewIssue = React.forwardRef(function HoverPreviewIssue_(
|
||||
</Flex>
|
||||
</Preview>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const StyledIssueStatusIcon = styled(IssueStatusIcon)`
|
||||
margin-top: 2px;
|
||||
|
||||
@@ -18,12 +18,16 @@ type Props = {
|
||||
thumbnailUrl: string;
|
||||
/** Some description about the link provider */
|
||||
description: string;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const HoverPreviewLink = React.forwardRef(function HoverPreviewLink_(
|
||||
{ url, thumbnailUrl, title, description }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
function HoverPreviewLink({
|
||||
url,
|
||||
thumbnailUrl,
|
||||
title,
|
||||
description,
|
||||
ref,
|
||||
}: Props) {
|
||||
return (
|
||||
<Preview as="a" href={url} target="_blank" rel="noopener noreferrer">
|
||||
<Flex column ref={ref}>
|
||||
@@ -39,6 +43,6 @@ const HoverPreviewLink = React.forwardRef(function HoverPreviewLink_(
|
||||
</Flex>
|
||||
</Preview>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export default HoverPreviewLink;
|
||||
@@ -4,12 +4,17 @@ import { Avatar, AvatarSize } from "~/components/Avatar";
|
||||
import Flex from "~/components/Flex";
|
||||
import { Preview, Title, Info, Card, CardContent } from "./Components";
|
||||
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Mention], "type">;
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.Mention], "type"> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const HoverPreviewMention = React.forwardRef(function HoverPreviewMention_(
|
||||
{ avatarUrl, name, lastActive, color }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
function HoverPreviewMention({
|
||||
avatarUrl,
|
||||
name,
|
||||
lastActive,
|
||||
color,
|
||||
ref,
|
||||
}: Props) {
|
||||
return (
|
||||
<Preview as="div">
|
||||
<Card fadeOut={false} ref={ref}>
|
||||
@@ -32,6 +37,6 @@ const HoverPreviewMention = React.forwardRef(function HoverPreviewMention_(
|
||||
</Card>
|
||||
</Preview>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export default HoverPreviewMention;
|
||||
@@ -30,12 +30,21 @@ type Props = Pick<
|
||||
| "state"
|
||||
| "targetDate"
|
||||
| "description"
|
||||
>;
|
||||
> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const HoverPreviewProject = React.forwardRef(function HoverPreviewProject_(
|
||||
{ url, name, color, lead, labels, state, description, targetDate }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
function HoverPreviewProject({
|
||||
url,
|
||||
name,
|
||||
color,
|
||||
lead,
|
||||
labels,
|
||||
state,
|
||||
description,
|
||||
targetDate,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
@@ -116,7 +125,7 @@ const HoverPreviewProject = React.forwardRef(function HoverPreviewProject_(
|
||||
</Flex>
|
||||
</Preview>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const StyledSquircle = styled(Squircle)`
|
||||
flex-shrink: 0;
|
||||
|
||||
@@ -19,57 +19,63 @@ import {
|
||||
Info,
|
||||
} from "./Components";
|
||||
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.PR], "type">;
|
||||
type Props = Omit<UnfurlResponse[UnfurlResourceType.PR], "type"> & {
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const HoverPreviewPullRequest = React.forwardRef(
|
||||
function HoverPreviewPullRequest_(
|
||||
{ url, title, id, description, author, state, createdAt }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
const authorName = author.name;
|
||||
function HoverPreviewPullRequest({
|
||||
url,
|
||||
title,
|
||||
id,
|
||||
description,
|
||||
author,
|
||||
state,
|
||||
createdAt,
|
||||
ref,
|
||||
}: Props) {
|
||||
const authorName = author.name;
|
||||
|
||||
return (
|
||||
<Preview as="a" href={url} target="_blank" rel="noopener noreferrer">
|
||||
<Flex column ref={ref}>
|
||||
<Card fadeOut={false}>
|
||||
<CardContent>
|
||||
<Flex gap={2} column>
|
||||
<Title>
|
||||
<StyledPullRequestIcon size={18} state={state} />
|
||||
<span>
|
||||
<Backticks content={title} />
|
||||
<Text type="tertiary">{id}</Text>
|
||||
</span>
|
||||
</Title>
|
||||
<Flex align="center" gap={6}>
|
||||
<Avatar src={author.avatarUrl} size={18} />
|
||||
<Info>
|
||||
<Trans>
|
||||
{{ authorName }} opened{" "}
|
||||
<Time dateTime={createdAt} addSuffix />
|
||||
</Trans>
|
||||
</Info>
|
||||
</Flex>
|
||||
{description && (
|
||||
<Description as="div">
|
||||
<React.Suspense fallback={<div />}>
|
||||
<Editor
|
||||
extensions={richExtensions}
|
||||
defaultValue={description}
|
||||
embedsDisabled
|
||||
readOnly
|
||||
/>
|
||||
</React.Suspense>
|
||||
</Description>
|
||||
)}
|
||||
return (
|
||||
<Preview as="a" href={url} target="_blank" rel="noopener noreferrer">
|
||||
<Flex column ref={ref}>
|
||||
<Card fadeOut={false}>
|
||||
<CardContent>
|
||||
<Flex gap={2} column>
|
||||
<Title>
|
||||
<StyledPullRequestIcon size={18} state={state} />
|
||||
<span>
|
||||
<Backticks content={title} />
|
||||
<Text type="tertiary">{id}</Text>
|
||||
</span>
|
||||
</Title>
|
||||
<Flex align="center" gap={6}>
|
||||
<Avatar src={author.avatarUrl} size={18} />
|
||||
<Info>
|
||||
<Trans>
|
||||
{{ authorName }} opened{" "}
|
||||
<Time dateTime={createdAt} addSuffix />
|
||||
</Trans>
|
||||
</Info>
|
||||
</Flex>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Flex>
|
||||
</Preview>
|
||||
);
|
||||
}
|
||||
);
|
||||
{description && (
|
||||
<Description as="div">
|
||||
<React.Suspense fallback={<div />}>
|
||||
<Editor
|
||||
extensions={richExtensions}
|
||||
defaultValue={description}
|
||||
embedsDisabled
|
||||
readOnly
|
||||
/>
|
||||
</React.Suspense>
|
||||
</Description>
|
||||
)}
|
||||
</Flex>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Flex>
|
||||
</Preview>
|
||||
);
|
||||
}
|
||||
|
||||
const StyledPullRequestIcon = styled(PullRequestIcon)`
|
||||
margin-top: 2px;
|
||||
|
||||
@@ -10,12 +10,18 @@ type Props = {
|
||||
columns: number;
|
||||
itemWidth: number;
|
||||
onOverflowChange?: (hasMoreBelow: boolean) => void;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const Grid = (
|
||||
{ width, height, data, columns, itemWidth, onOverflowChange }: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) => {
|
||||
function Grid({
|
||||
width,
|
||||
height,
|
||||
data,
|
||||
columns,
|
||||
itemWidth,
|
||||
onOverflowChange,
|
||||
ref,
|
||||
}: Props) {
|
||||
const offsetRef = React.useRef(0);
|
||||
const maxOffset = Math.max(0, data.length * itemWidth - height);
|
||||
|
||||
@@ -47,7 +53,7 @@ const Grid = (
|
||||
{Row}
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
type RowProps = {
|
||||
data: React.ReactNode[][];
|
||||
@@ -82,4 +88,4 @@ const RowContainer = styled.div<{ columns: number }>`
|
||||
align-content: center;
|
||||
`;
|
||||
|
||||
export default React.forwardRef(Grid);
|
||||
export default Grid;
|
||||
@@ -58,20 +58,20 @@ type Props = {
|
||||
onIconActive?: (icon: IconNode) => void;
|
||||
/** Callback when whether the grid has content below the fold changes */
|
||||
onOverflowChange?: (hasMoreBelow: boolean) => void;
|
||||
/** Ref to the scrolling container */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const GridTemplate = (
|
||||
{
|
||||
width,
|
||||
height,
|
||||
data,
|
||||
empty,
|
||||
onIconSelect,
|
||||
onIconActive,
|
||||
onOverflowChange,
|
||||
}: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) => {
|
||||
function GridTemplate({
|
||||
width,
|
||||
height,
|
||||
data,
|
||||
empty,
|
||||
onIconSelect,
|
||||
onIconActive,
|
||||
onOverflowChange,
|
||||
ref,
|
||||
}: Props) {
|
||||
const isMobile = useMobile();
|
||||
const buttonSize = isMobile ? BUTTON_SIZE_MOBILE : BUTTON_SIZE_DESKTOP;
|
||||
const iconSize = isMobile ? ICON_SIZE_MOBILE : ICON_SIZE_DESKTOP;
|
||||
@@ -159,7 +159,7 @@ const GridTemplate = (
|
||||
onOverflowChange={onOverflowChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const CategoryName = styled(Text)`
|
||||
grid-column: 1 / -1;
|
||||
@@ -173,4 +173,4 @@ const Icon = styled.svg`
|
||||
transition-delay: var(--delay);
|
||||
`;
|
||||
|
||||
export default React.forwardRef(GridTemplate);
|
||||
export default GridTemplate;
|
||||
@@ -0,0 +1,30 @@
|
||||
interface GmailIconProps {
|
||||
size?: number;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Gmail logo as a decorative icon.
|
||||
*
|
||||
* @param props the icon size and color.
|
||||
* @returns the Gmail logo.
|
||||
* @see https://github.com/simple-icons/simple-icons/blob/12.4.0/icons/gmail.svg
|
||||
*/
|
||||
export function GmailIcon({
|
||||
size = 24,
|
||||
color = "currentColor",
|
||||
}: GmailIconProps) {
|
||||
return (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox="-4 -4 32 32"
|
||||
fill={color}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
>
|
||||
<path d="M24 5.457v13.909c0 .904-.732 1.636-1.636 1.636h-3.819V11.73L12 16.64l-6.545-4.91v9.273H1.636A1.636 1.636 0 0 1 0 19.366V5.457c0-2.023 2.309-3.178 3.927-1.964L5.455 4.64 12 9.548l6.545-4.91 1.528-1.145C21.69 2.28 24 3.434 24 5.457z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
interface OutlookIconProps {
|
||||
size?: number;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Outlook logo as a decorative icon.
|
||||
*
|
||||
* @param props the icon size and color.
|
||||
* @returns the Outlook logo.
|
||||
* @see https://github.com/simple-icons/simple-icons/blob/12.4.0/icons/microsoftoutlook.svg
|
||||
*/
|
||||
export function OutlookIcon({
|
||||
size = 24,
|
||||
color = "currentColor",
|
||||
}: OutlookIconProps) {
|
||||
return (
|
||||
<svg
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox="-4 -4 32 32"
|
||||
fill={color}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
>
|
||||
<path d="M7.88 12.04q0 .45-.11.87-.1.41-.33.74-.22.33-.58.52-.37.2-.87.2t-.85-.2q-.35-.21-.57-.55-.22-.33-.33-.75-.1-.42-.1-.86t.1-.87q.1-.43.34-.76.22-.34.59-.54.36-.2.87-.2t.86.2q.35.21.57.55.22.34.31.77.1.43.1.88zM24 12v9.38q0 .46-.33.8-.33.32-.8.32H7.13q-.46 0-.8-.33-.32-.33-.32-.8V18H1q-.41 0-.7-.3-.3-.29-.3-.7V7q0-.41.3-.7Q.58 6 1 6h6.5V2.55q0-.44.3-.75.3-.3.75-.3h12.9q.44 0 .75.3.3.3.3.75V10.85l1.24.72h.01q.1.07.18.18.07.12.07.25zm-6-8.25v3h3v-3zm0 4.5v3h3v-3zm0 4.5v1.83l3.05-1.83zm-5.25-9v3h3.75v-3zm0 4.5v3h3.75v-3zm0 4.5v2.03l2.41 1.5 1.34-.8v-2.73zM9 3.75V6h2l.13.01.12.04v-2.3zM5.98 15.98q.9 0 1.6-.3.7-.32 1.19-.86.48-.55.73-1.28.25-.74.25-1.61 0-.83-.25-1.55-.24-.71-.71-1.24t-1.15-.83q-.68-.3-1.55-.3-.92 0-1.64.3-.71.3-1.2.85-.5.54-.75 1.3-.25.74-.25 1.63 0 .85.26 1.56.26.72.74 1.23.48.52 1.17.81.69.3 1.56.3zM7.5 21h12.39L12 16.08V17q0 .41-.3.7-.29.3-.7.3H7.5zm15-.13v-7.24l-5.9 3.54Z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -192,10 +192,11 @@ export interface Props extends Omit<
|
||||
}
|
||||
|
||||
function Input(
|
||||
props: Props,
|
||||
ref: React.RefObject<HTMLInputElement | HTMLTextAreaElement>
|
||||
props: Props & { ref?: React.Ref<HTMLInputElement | HTMLTextAreaElement> }
|
||||
) {
|
||||
const internalRef = React.useRef<HTMLInputElement | HTMLTextAreaElement>();
|
||||
const internalRef = React.useRef<
|
||||
HTMLInputElement | HTMLTextAreaElement | undefined
|
||||
>(undefined);
|
||||
const [focused, setFocused] = React.useState(false);
|
||||
const [charCount, setCharCount] = React.useState(() => {
|
||||
if (typeof props.value === "string") {
|
||||
@@ -282,6 +283,7 @@ function Input(
|
||||
onChange,
|
||||
onRequestSubmit,
|
||||
children,
|
||||
ref,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -322,7 +324,7 @@ function Input(
|
||||
<NativeTextarea
|
||||
ref={mergeRefs([
|
||||
internalRef,
|
||||
ref as React.RefObject<HTMLTextAreaElement>,
|
||||
ref as React.Ref<HTMLTextAreaElement>,
|
||||
])}
|
||||
onBlur={handleBlur}
|
||||
onFocus={handleFocus}
|
||||
@@ -340,10 +342,7 @@ function Input(
|
||||
/>
|
||||
) : (
|
||||
<NativeInput
|
||||
ref={mergeRefs([
|
||||
internalRef,
|
||||
ref as React.RefObject<HTMLInputElement>,
|
||||
])}
|
||||
ref={mergeRefs([internalRef, ref as React.Ref<HTMLInputElement>])}
|
||||
onBlur={handleBlur}
|
||||
onFocus={handleFocus}
|
||||
hasIcon={!!icon}
|
||||
@@ -384,4 +383,4 @@ export const TextWrapper = styled.span`
|
||||
margin-top: -16px;
|
||||
`;
|
||||
|
||||
export default React.forwardRef(Input);
|
||||
export default Input;
|
||||
@@ -12,12 +12,10 @@ type Props = InputProps & {
|
||||
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => unknown;
|
||||
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => unknown;
|
||||
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => unknown;
|
||||
ref?: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
|
||||
};
|
||||
|
||||
function InputSearch(
|
||||
props: Props,
|
||||
ref: React.RefObject<HTMLInputElement | HTMLTextAreaElement>
|
||||
) {
|
||||
function InputSearch(props: Props) {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const [isFocused, setIsFocused] = React.useState(false);
|
||||
@@ -26,6 +24,7 @@ function InputSearch(
|
||||
onKeyDown,
|
||||
onBlur,
|
||||
onFocus,
|
||||
ref,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -65,4 +64,4 @@ function InputSearch(
|
||||
);
|
||||
}
|
||||
|
||||
export default React.forwardRef(InputSearch);
|
||||
export default InputSearch;
|
||||
+219
-221
@@ -77,139 +77,138 @@ type Props = Omit<React.HTMLAttributes<HTMLButtonElement>, "onChange"> & {
|
||||
help?: string;
|
||||
/** Render function to override the selected value shown in the trigger. Receives the currently selected option, or undefined when none is selected. */
|
||||
displayValue?: (selectedOption: Item | undefined) => React.ReactNode;
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
} & TriggerButtonProps;
|
||||
|
||||
export const InputSelect = React.forwardRef<HTMLButtonElement, Props>(
|
||||
(props, ref) => {
|
||||
const {
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
labelHidden,
|
||||
short,
|
||||
help,
|
||||
displayValue,
|
||||
...triggerProps
|
||||
} = props;
|
||||
export function InputSelect(props: Props) {
|
||||
const {
|
||||
ref,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
labelHidden,
|
||||
short,
|
||||
help,
|
||||
displayValue,
|
||||
...triggerProps
|
||||
} = props;
|
||||
|
||||
const [localValue, setLocalValue] = React.useState(value);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [localValue, setLocalValue] = React.useState(value);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
const contentRef =
|
||||
React.useRef<React.ElementRef<typeof InputSelectContent>>(null);
|
||||
const contentRef =
|
||||
React.useRef<React.ComponentRef<typeof InputSelectContent>>(null);
|
||||
|
||||
const isMobile = useMobile();
|
||||
const isMobile = useMobile();
|
||||
|
||||
const placeholder = `Select a ${label.toLowerCase()}`;
|
||||
const optionsHaveIcon = options.some(
|
||||
(opt) => opt.type === "item" && !!opt.icon
|
||||
);
|
||||
const placeholder = `Select a ${label.toLowerCase()}`;
|
||||
const optionsHaveIcon = options.some(
|
||||
(opt) => opt.type === "item" && !!opt.icon
|
||||
);
|
||||
|
||||
const selectedOption = React.useMemo(
|
||||
() =>
|
||||
localValue
|
||||
? (options.find(
|
||||
(opt) => opt.type === "item" && opt.value === localValue
|
||||
) as Item | undefined)
|
||||
: undefined,
|
||||
[localValue, options]
|
||||
);
|
||||
const selectedOption = React.useMemo(
|
||||
() =>
|
||||
localValue
|
||||
? (options.find(
|
||||
(opt) => opt.type === "item" && opt.value === localValue
|
||||
) as Item | undefined)
|
||||
: undefined,
|
||||
[localValue, options]
|
||||
);
|
||||
|
||||
const resolvedDisplayValue = displayValue
|
||||
? displayValue(selectedOption)
|
||||
: undefined;
|
||||
const resolvedDisplayValue = displayValue
|
||||
? displayValue(selectedOption)
|
||||
: undefined;
|
||||
|
||||
const renderOption = React.useCallback(
|
||||
(option: Option, idx: number) => {
|
||||
if (option.type === "separator") {
|
||||
return <InputSelectSeparator key={`separator-${idx}`} />;
|
||||
}
|
||||
|
||||
if (option.type === "heading") {
|
||||
return (
|
||||
<InputSelectHeading key={`heading-${option.label}`}>
|
||||
{option.label}
|
||||
</InputSelectHeading>
|
||||
);
|
||||
}
|
||||
const renderOption = React.useCallback(
|
||||
(option: Option, idx: number) => {
|
||||
if (option.type === "separator") {
|
||||
return <InputSelectSeparator key={`separator-${idx}`} />;
|
||||
}
|
||||
|
||||
if (option.type === "heading") {
|
||||
return (
|
||||
<InputSelectItem key={option.value} value={option.value}>
|
||||
<Option option={option} optionsHaveIcon={optionsHaveIcon} />
|
||||
</InputSelectItem>
|
||||
<InputSelectHeading key={`heading-${option.label}`}>
|
||||
{option.label}
|
||||
</InputSelectHeading>
|
||||
);
|
||||
},
|
||||
[optionsHaveIcon]
|
||||
);
|
||||
|
||||
const onValueChange = React.useCallback(
|
||||
async (val: string) => {
|
||||
setLocalValue(val);
|
||||
onChange(val);
|
||||
},
|
||||
[onChange, setLocalValue]
|
||||
);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "auto";
|
||||
}
|
||||
}, []);
|
||||
|
||||
const disablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "none";
|
||||
}
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
setLocalValue(value);
|
||||
}, [value]);
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<MobileSelect
|
||||
ref={ref}
|
||||
{...props}
|
||||
value={localValue}
|
||||
onChange={onValueChange}
|
||||
placeholder={placeholder}
|
||||
optionsHaveIcon={optionsHaveIcon}
|
||||
resolvedDisplayValue={resolvedDisplayValue}
|
||||
/>
|
||||
<InputSelectItem key={option.value} value={option.value}>
|
||||
<Option option={option} optionsHaveIcon={optionsHaveIcon} />
|
||||
</InputSelectItem>
|
||||
);
|
||||
}
|
||||
},
|
||||
[optionsHaveIcon]
|
||||
);
|
||||
|
||||
const onValueChange = React.useCallback(
|
||||
async (val: string) => {
|
||||
setLocalValue(val);
|
||||
onChange(val);
|
||||
},
|
||||
[onChange, setLocalValue]
|
||||
);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "auto";
|
||||
}
|
||||
}, []);
|
||||
|
||||
const disablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "none";
|
||||
}
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
setLocalValue(value);
|
||||
}, [value]);
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Wrapper short={short}>
|
||||
<Label text={label} hidden={labelHidden ?? false} help={help} />
|
||||
<InputSelectRoot
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
value={localValue ?? undefined}
|
||||
onValueChange={onValueChange}
|
||||
>
|
||||
<InputSelectTrigger
|
||||
ref={ref}
|
||||
placeholder={placeholder}
|
||||
displayValue={resolvedDisplayValue}
|
||||
{...triggerProps}
|
||||
/>
|
||||
<InputSelectContent
|
||||
ref={contentRef}
|
||||
aria-label={label}
|
||||
onAnimationStart={disablePointerEvents}
|
||||
onAnimationEnd={enablePointerEvents}
|
||||
>
|
||||
{options.map(renderOption)}
|
||||
</InputSelectContent>
|
||||
</InputSelectRoot>
|
||||
</Wrapper>
|
||||
<MobileSelect
|
||||
ref={ref}
|
||||
{...props}
|
||||
value={localValue}
|
||||
onChange={onValueChange}
|
||||
placeholder={placeholder}
|
||||
optionsHaveIcon={optionsHaveIcon}
|
||||
resolvedDisplayValue={resolvedDisplayValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
InputSelect.displayName = "InputSelect";
|
||||
|
||||
return (
|
||||
<Wrapper short={short}>
|
||||
<Label text={label} hidden={labelHidden ?? false} help={help} />
|
||||
<InputSelectRoot
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
value={localValue ?? undefined}
|
||||
onValueChange={onValueChange}
|
||||
>
|
||||
<InputSelectTrigger
|
||||
ref={ref}
|
||||
placeholder={placeholder}
|
||||
displayValue={resolvedDisplayValue}
|
||||
{...triggerProps}
|
||||
/>
|
||||
<InputSelectContent
|
||||
ref={contentRef}
|
||||
aria-label={label}
|
||||
onAnimationStart={disablePointerEvents}
|
||||
onAnimationEnd={enablePointerEvents}
|
||||
>
|
||||
{options.map(renderOption)}
|
||||
</InputSelectContent>
|
||||
</InputSelectRoot>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
type MobileSelectProps = Props & {
|
||||
placeholder: string;
|
||||
@@ -217,125 +216,124 @@ type MobileSelectProps = Props & {
|
||||
resolvedDisplayValue?: React.ReactNode;
|
||||
};
|
||||
|
||||
const MobileSelect = React.forwardRef<HTMLButtonElement, MobileSelectProps>(
|
||||
(props, ref) => {
|
||||
const {
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
labelHidden,
|
||||
disabled,
|
||||
short,
|
||||
placeholder,
|
||||
optionsHaveIcon,
|
||||
displayValue: _displayValue,
|
||||
resolvedDisplayValue,
|
||||
...triggerProps
|
||||
} = props;
|
||||
function MobileSelect(props: MobileSelectProps) {
|
||||
const {
|
||||
ref,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
labelHidden,
|
||||
disabled,
|
||||
short,
|
||||
placeholder,
|
||||
optionsHaveIcon,
|
||||
displayValue: _displayValue,
|
||||
resolvedDisplayValue,
|
||||
...triggerProps
|
||||
} = props;
|
||||
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const contentRef =
|
||||
React.useRef<React.ElementRef<typeof DrawerContent>>(null);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const contentRef =
|
||||
React.useRef<React.ComponentRef<typeof DrawerContent>>(null);
|
||||
|
||||
const selectedOption = React.useMemo(
|
||||
() =>
|
||||
value
|
||||
? options.find((opt) => opt.type === "item" && opt.value === value)
|
||||
: undefined,
|
||||
[value, options]
|
||||
);
|
||||
const selectedOption = React.useMemo(
|
||||
() =>
|
||||
value
|
||||
? options.find((opt) => opt.type === "item" && opt.value === value)
|
||||
: undefined,
|
||||
[value, options]
|
||||
);
|
||||
|
||||
const handleSelect = React.useCallback(
|
||||
async (val: string) => {
|
||||
setOpen(false);
|
||||
onChange(val);
|
||||
},
|
||||
[onChange]
|
||||
);
|
||||
const handleSelect = React.useCallback(
|
||||
async (val: string) => {
|
||||
setOpen(false);
|
||||
onChange(val);
|
||||
},
|
||||
[onChange]
|
||||
);
|
||||
|
||||
const renderOption = React.useCallback(
|
||||
(option: Option, idx: number) => {
|
||||
if (option.type === "separator") {
|
||||
return <InputSelectSeparator key={`separator-${idx}`} />;
|
||||
}
|
||||
|
||||
if (option.type === "heading") {
|
||||
return (
|
||||
<InputSelectHeading key={`heading-${option.label}`}>
|
||||
{option.label}
|
||||
</InputSelectHeading>
|
||||
);
|
||||
}
|
||||
|
||||
const isSelected = option === selectedOption;
|
||||
const renderOption = React.useCallback(
|
||||
(option: Option, idx: number) => {
|
||||
if (option.type === "separator") {
|
||||
return <InputSelectSeparator key={`separator-${idx}`} />;
|
||||
}
|
||||
|
||||
if (option.type === "heading") {
|
||||
return (
|
||||
<SelectItemWrapper
|
||||
key={option.value}
|
||||
onClick={() => handleSelect(option.value)}
|
||||
data-state={isSelected ? "checked" : "unchecked"}
|
||||
>
|
||||
<Option option={option} optionsHaveIcon={optionsHaveIcon} />
|
||||
{isSelected && <SelectItemIndicator />}
|
||||
</SelectItemWrapper>
|
||||
<InputSelectHeading key={`heading-${option.label}`}>
|
||||
{option.label}
|
||||
</InputSelectHeading>
|
||||
);
|
||||
},
|
||||
[handleSelect, selectedOption, optionsHaveIcon]
|
||||
);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "auto";
|
||||
}
|
||||
}, []);
|
||||
|
||||
const disablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "none";
|
||||
}
|
||||
}, []);
|
||||
const isSelected = option === selectedOption;
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<Label text={label} hidden={labelHidden ?? false} />
|
||||
<Drawer open={open} onOpenChange={setOpen}>
|
||||
<DrawerTrigger asChild>
|
||||
<SelectButton
|
||||
ref={ref}
|
||||
{...triggerProps}
|
||||
neutral
|
||||
disclosure
|
||||
data-placeholder={selectedOption ? false : ""}
|
||||
>
|
||||
{resolvedDisplayValue !== undefined ? (
|
||||
resolvedDisplayValue
|
||||
) : selectedOption ? (
|
||||
<Option
|
||||
option={selectedOption as Item}
|
||||
optionsHaveIcon={optionsHaveIcon}
|
||||
/>
|
||||
) : (
|
||||
<>{placeholder}</>
|
||||
)}
|
||||
</SelectButton>
|
||||
</DrawerTrigger>
|
||||
<DrawerContent
|
||||
ref={contentRef}
|
||||
aria-label={label}
|
||||
onAnimationStart={disablePointerEvents}
|
||||
onAnimationEnd={enablePointerEvents}
|
||||
return (
|
||||
<SelectItemWrapper
|
||||
key={option.value}
|
||||
onClick={() => handleSelect(option.value)}
|
||||
data-state={isSelected ? "checked" : "unchecked"}
|
||||
>
|
||||
<Option option={option} optionsHaveIcon={optionsHaveIcon} />
|
||||
{isSelected && <SelectItemIndicator />}
|
||||
</SelectItemWrapper>
|
||||
);
|
||||
},
|
||||
[handleSelect, selectedOption, optionsHaveIcon]
|
||||
);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "auto";
|
||||
}
|
||||
}, []);
|
||||
|
||||
const disablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "none";
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<Label text={label} hidden={labelHidden ?? false} />
|
||||
<Drawer open={open} onOpenChange={setOpen}>
|
||||
<DrawerTrigger asChild>
|
||||
<SelectButton
|
||||
ref={ref}
|
||||
{...triggerProps}
|
||||
neutral
|
||||
disclosure
|
||||
data-placeholder={selectedOption ? false : ""}
|
||||
>
|
||||
<DrawerTitle hidden={!label}>{label}</DrawerTitle>
|
||||
<StyledScrollable hiddenScrollbars>
|
||||
{options.map(renderOption)}
|
||||
</StyledScrollable>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
);
|
||||
{resolvedDisplayValue !== undefined ? (
|
||||
resolvedDisplayValue
|
||||
) : selectedOption ? (
|
||||
<Option
|
||||
option={selectedOption as Item}
|
||||
optionsHaveIcon={optionsHaveIcon}
|
||||
/>
|
||||
) : (
|
||||
<>{placeholder}</>
|
||||
)}
|
||||
</SelectButton>
|
||||
</DrawerTrigger>
|
||||
<DrawerContent
|
||||
ref={contentRef}
|
||||
aria-label={label}
|
||||
onAnimationStart={disablePointerEvents}
|
||||
onAnimationEnd={enablePointerEvents}
|
||||
>
|
||||
<DrawerTitle hidden={!label}>{label}</DrawerTitle>
|
||||
<StyledScrollable hiddenScrollbars>
|
||||
{options.map(renderOption)}
|
||||
</StyledScrollable>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
MobileSelect.displayName = "InputSelect";
|
||||
|
||||
function Label({
|
||||
|
||||
@@ -9,54 +9,52 @@ import { EmptySelectValue } from "~/types";
|
||||
|
||||
type Props = {
|
||||
shrink?: boolean;
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
} & Pick<
|
||||
React.ComponentProps<typeof InputSelect>,
|
||||
"value" | "onChange" | "disabled" | "labelHidden" | "nude" | "help"
|
||||
>;
|
||||
|
||||
export const InputSelectPermission = React.forwardRef<HTMLButtonElement, Props>(
|
||||
(props, ref) => {
|
||||
const { value, onChange, shrink, ...rest } = props;
|
||||
const { t } = useTranslation();
|
||||
export function InputSelectPermission(props: Props) {
|
||||
const { ref, value, onChange, shrink, ...rest } = props;
|
||||
const { t } = useTranslation();
|
||||
|
||||
const options = React.useMemo<Option[]>(
|
||||
() => [
|
||||
{
|
||||
type: "item",
|
||||
label: t("View only"),
|
||||
value: CollectionPermission.Read,
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: t("Can edit"),
|
||||
value: CollectionPermission.ReadWrite,
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: t("No access"),
|
||||
value: EmptySelectValue,
|
||||
},
|
||||
],
|
||||
[t]
|
||||
);
|
||||
const options = React.useMemo<Option[]>(
|
||||
() => [
|
||||
{
|
||||
type: "item",
|
||||
label: t("View only"),
|
||||
value: CollectionPermission.Read,
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: t("Can edit"),
|
||||
value: CollectionPermission.ReadWrite,
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: t("No access"),
|
||||
value: EmptySelectValue,
|
||||
},
|
||||
],
|
||||
[t]
|
||||
);
|
||||
|
||||
return (
|
||||
<Select
|
||||
ref={ref}
|
||||
options={options}
|
||||
value={value || EmptySelectValue}
|
||||
onChange={onChange}
|
||||
label={t("Permission")}
|
||||
$shrink={shrink}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
InputSelectPermission.displayName = "InputSelectPermission";
|
||||
return (
|
||||
<Select
|
||||
ref={ref}
|
||||
options={options}
|
||||
value={value || EmptySelectValue}
|
||||
onChange={onChange}
|
||||
label={t("Permission")}
|
||||
$shrink={shrink}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const Select = styled(InputSelect)<{ $shrink?: boolean }>`
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
+37
-35
@@ -1,13 +1,13 @@
|
||||
import { AnimatePresence } from "framer-motion";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { Helmet } from "react-helmet-async";
|
||||
import type { DefaultTheme } from "styled-components";
|
||||
import styled from "styled-components";
|
||||
import breakpoint from "styled-components-breakpoint";
|
||||
import { s } from "@shared/styles";
|
||||
import Flex from "~/components/Flex";
|
||||
import { LoadingIndicatorBar } from "~/components/LoadingIndicator";
|
||||
import { FallbackPageTitle } from "~/components/PageTitle";
|
||||
import { useRightSidebarContent } from "~/components/RightSidebarContext";
|
||||
import SkipNavContent from "~/components/SkipNavContent";
|
||||
import SkipNavLink from "~/components/SkipNavLink";
|
||||
@@ -23,12 +23,16 @@ type Props = {
|
||||
sidebar?: React.ReactNode;
|
||||
/** Whether the sidebar can be collapsed, defaults to true. */
|
||||
sidebarCanCollapse?: boolean;
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const Layout = React.forwardRef(function Layout_(
|
||||
{ title, children, sidebar, sidebarCanCollapse = true }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
function Layout({
|
||||
title,
|
||||
children,
|
||||
sidebar,
|
||||
sidebarCanCollapse = true,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { ui } = useStores();
|
||||
const showSidebar = !!sidebar && !ui.sidebarHidden;
|
||||
const sidebarCollapsed =
|
||||
@@ -36,42 +40,40 @@ const Layout = React.forwardRef(function Layout_(
|
||||
const sidebarRight = useRightSidebarContent();
|
||||
|
||||
return (
|
||||
<Container column auto ref={ref}>
|
||||
<Helmet>
|
||||
<title>{title ? title : env.APP_NAME}</title>
|
||||
</Helmet>
|
||||
<FallbackPageTitle title={title ? title : env.APP_NAME}>
|
||||
<Container column auto ref={ref}>
|
||||
<SkipNavLink />
|
||||
|
||||
<SkipNavLink />
|
||||
{ui.progressBarVisible && <LoadingIndicatorBar />}
|
||||
|
||||
{ui.progressBarVisible && <LoadingIndicatorBar />}
|
||||
<Container auto>
|
||||
{showSidebar && sidebar}
|
||||
|
||||
<Container auto>
|
||||
{showSidebar && sidebar}
|
||||
<SkipNavContent />
|
||||
<Content
|
||||
auto
|
||||
justify="center"
|
||||
role="main"
|
||||
$isResizing={ui.sidebarIsResizing}
|
||||
$sidebarCollapsed={sidebarCollapsed}
|
||||
$hasSidebar={showSidebar}
|
||||
style={
|
||||
sidebarCollapsed
|
||||
? undefined
|
||||
: {
|
||||
marginInlineStart: `${ui.sidebarWidth}px`,
|
||||
}
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</Content>
|
||||
|
||||
<SkipNavContent />
|
||||
<Content
|
||||
auto
|
||||
justify="center"
|
||||
role="main"
|
||||
$isResizing={ui.sidebarIsResizing}
|
||||
$sidebarCollapsed={sidebarCollapsed}
|
||||
$hasSidebar={showSidebar}
|
||||
style={
|
||||
sidebarCollapsed
|
||||
? undefined
|
||||
: {
|
||||
marginInlineStart: `${ui.sidebarWidth}px`,
|
||||
}
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</Content>
|
||||
|
||||
<AnimatePresence initial={false}>{sidebarRight}</AnimatePresence>
|
||||
<AnimatePresence initial={false}>{sidebarRight}</AnimatePresence>
|
||||
</Container>
|
||||
</Container>
|
||||
</Container>
|
||||
</FallbackPageTitle>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const Container = styled(Flex)`
|
||||
background: ${s("background")};
|
||||
|
||||
+41
-38
@@ -6,11 +6,11 @@ import type {
|
||||
ComponentProps,
|
||||
HTMLAttributes,
|
||||
ReactNode,
|
||||
Ref,
|
||||
SyntheticEvent,
|
||||
} from "react";
|
||||
import {
|
||||
createContext,
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
@@ -142,12 +142,16 @@ type ZoomablePannablePinchableProps = {
|
||||
panningDisabled: boolean;
|
||||
disabled: boolean;
|
||||
onClose?: () => void;
|
||||
ref?: Ref<ReactZoomPanPinchRef>;
|
||||
};
|
||||
|
||||
const ZoomablePannablePinchable = forwardRef<
|
||||
ReactZoomPanPinchRef,
|
||||
ZoomablePannablePinchableProps
|
||||
>(({ children, panningDisabled, disabled, onClose }, ref) => {
|
||||
function ZoomablePannablePinchable({
|
||||
children,
|
||||
panningDisabled,
|
||||
disabled,
|
||||
onClose,
|
||||
ref,
|
||||
}: ZoomablePannablePinchableProps) {
|
||||
const { isPanning, ...panningHandlers } = usePanning();
|
||||
const wrapperRef = useRef<ReactZoomPanPinchRef>(null);
|
||||
const scale = wrapperRef.current?.instance.transformState.scale ?? 1;
|
||||
@@ -208,7 +212,7 @@ const ZoomablePannablePinchable = forwardRef<
|
||||
</TransformWrapper>
|
||||
</ZoomPanPinchContext.Provider>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function usePanning() {
|
||||
const [isPanning, setPanning] = useState(false);
|
||||
@@ -616,12 +620,12 @@ function Lightbox({ images, activeImage, onUpdate, onClose, readOnly }: Props) {
|
||||
}, [status.image]);
|
||||
|
||||
// Hide the inline image in the editor while the lightbox zoom transition is
|
||||
// active, otherwise a duplicate is visible behind the fading overlay.
|
||||
// active, otherwise a duplicate is visible behind the fading overlay. It stays
|
||||
// hidden until unmount so the lightbox copy is the only one visible in any
|
||||
// frame painted between the close animation ending and the teardown.
|
||||
useHideElement(
|
||||
activeImage.getElement(),
|
||||
status.lightbox !== null &&
|
||||
status.lightbox !== LightboxStatus.READY_TO_OPEN &&
|
||||
status.lightbox !== LightboxStatus.CLOSED
|
||||
status.lightbox !== null && status.lightbox !== LightboxStatus.READY_TO_OPEN
|
||||
);
|
||||
|
||||
const prev = () => {
|
||||
@@ -993,27 +997,26 @@ type ImageProps = {
|
||||
onMinZoom: () => void;
|
||||
onZoom: () => void;
|
||||
onMaxZoom: () => void;
|
||||
ref?: Ref<HTMLImageElement>;
|
||||
};
|
||||
|
||||
const Image = forwardRef<HTMLImageElement, ImageProps>(function Image_(
|
||||
{
|
||||
src,
|
||||
alt,
|
||||
onLoading,
|
||||
onLoad,
|
||||
onError,
|
||||
onSwipeRight,
|
||||
onSwipeLeft,
|
||||
onSwipeUp,
|
||||
onSwipeDown,
|
||||
status,
|
||||
animation,
|
||||
onMinZoom,
|
||||
onZoom,
|
||||
onMaxZoom,
|
||||
}: ImageProps,
|
||||
ref
|
||||
) {
|
||||
function Image({
|
||||
src,
|
||||
alt,
|
||||
onLoading,
|
||||
onLoad,
|
||||
onError,
|
||||
onSwipeRight,
|
||||
onSwipeLeft,
|
||||
onSwipeUp,
|
||||
onSwipeDown,
|
||||
status,
|
||||
animation,
|
||||
onMinZoom,
|
||||
onZoom,
|
||||
onMaxZoom,
|
||||
ref,
|
||||
}: ImageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const swipeHandlers = useSwipe({
|
||||
@@ -1091,7 +1094,7 @@ const Image = forwardRef<HTMLImageElement, ImageProps>(function Image_(
|
||||
</Figure>
|
||||
</>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const Figure = styled("figure")`
|
||||
width: 100%;
|
||||
@@ -1132,7 +1135,7 @@ const StyledOverlay = styled(Dialog.Overlay)<{
|
||||
: props.animation.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
@@ -1167,12 +1170,12 @@ const StyledImg = styled.img<{
|
||||
: props.animation?.zoomOut
|
||||
? css`
|
||||
animation: ${props.animation.zoomOut.apply()}
|
||||
${props.animation.zoomOut.duration}ms;
|
||||
${props.animation.zoomOut.duration}ms forwards;
|
||||
`
|
||||
: props.animation?.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
@@ -1220,7 +1223,7 @@ const Actions = styled(HStack)<{
|
||||
: props.animation.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
@@ -1248,7 +1251,7 @@ const CloseAction = styled.div<{ animation: Animation | null }>`
|
||||
: props.animation.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
@@ -1282,7 +1285,7 @@ const Nav = styled.div<{
|
||||
: props.animation.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
@@ -1303,7 +1306,7 @@ const StyledError = styled(ImageError)<{
|
||||
: props.animation.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
@@ -1324,7 +1327,7 @@ const CommentsSidebar = styled.div<{
|
||||
props.animation?.fadeOut
|
||||
? css`
|
||||
animation: ${props.animation.fadeOut.apply()}
|
||||
${props.animation.fadeOut.duration}ms;
|
||||
${props.animation.fadeOut.duration}ms forwards;
|
||||
`
|
||||
: ""}
|
||||
`;
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
useFocusEffect,
|
||||
useRovingTabIndex,
|
||||
} from "@getoutline/react-roving-tabindex";
|
||||
import type { LocationDescriptor } from "history";
|
||||
import * as React from "react";
|
||||
import scrollIntoView from "scroll-into-view-if-needed";
|
||||
@@ -9,6 +5,7 @@ import styled, { useTheme } from "styled-components";
|
||||
import { s, hover, ellipsis } from "@shared/styles";
|
||||
import Flex from "~/components/Flex";
|
||||
import NavLink from "~/components/NavLink";
|
||||
import { useRovingTabIndex } from "~/hooks/useRovingTabIndex";
|
||||
|
||||
export type Props = Omit<React.HTMLAttributes<HTMLAnchorElement>, "title"> & {
|
||||
/** An icon or image to display to the left of the list item */
|
||||
@@ -34,27 +31,27 @@ export type Props = Omit<React.HTMLAttributes<HTMLAnchorElement>, "title"> & {
|
||||
/** Whether to enable keyboard navigation */
|
||||
keyboardNavigation?: boolean;
|
||||
enableEllipsis?: boolean;
|
||||
/** Ref to the anchor element */
|
||||
ref?: React.RefObject<HTMLAnchorElement | null>;
|
||||
};
|
||||
|
||||
const ListItem = (
|
||||
{
|
||||
image,
|
||||
title,
|
||||
subtitle,
|
||||
actions,
|
||||
small,
|
||||
border,
|
||||
to,
|
||||
keyboardNavigation,
|
||||
enableEllipsis,
|
||||
...rest
|
||||
}: Props,
|
||||
ref: React.RefObject<HTMLAnchorElement>
|
||||
) => {
|
||||
function ListItem({
|
||||
image,
|
||||
title,
|
||||
subtitle,
|
||||
actions,
|
||||
small,
|
||||
border,
|
||||
to,
|
||||
keyboardNavigation,
|
||||
enableEllipsis,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
const theme = useTheme();
|
||||
const compact = !subtitle;
|
||||
|
||||
let itemRef: React.RefObject<HTMLAnchorElement> =
|
||||
let itemRef: React.RefObject<HTMLAnchorElement | null> =
|
||||
React.useRef<HTMLAnchorElement>(null);
|
||||
if (ref) {
|
||||
itemRef = ref;
|
||||
@@ -64,7 +61,6 @@ const ListItem = (
|
||||
itemRef,
|
||||
keyboardNavigation || to ? false : true
|
||||
);
|
||||
useFocusEffect(focused, itemRef);
|
||||
|
||||
const handleFocus = React.useCallback(() => {
|
||||
if (itemRef.current) {
|
||||
@@ -165,7 +161,7 @@ const ListItem = (
|
||||
{content(false)}
|
||||
</Wrapper>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const Wrapper = styled.a<{
|
||||
$small?: boolean;
|
||||
@@ -241,4 +237,4 @@ export const Actions = styled(Flex)<{ $selected?: boolean }>`
|
||||
color: ${s("textSecondary")};
|
||||
`;
|
||||
|
||||
export default React.forwardRef(ListItem);
|
||||
export default ListItem;
|
||||
@@ -8,8 +8,8 @@ const LoadingIndicatorBar = () => (
|
||||
);
|
||||
|
||||
const loadingFrame = keyframes`
|
||||
from { margin-left: -100%; }
|
||||
to { margin-left: 100%; }
|
||||
from { transform: translateX(-100%); }
|
||||
to { transform: translateX(100%); }
|
||||
`;
|
||||
|
||||
const Container = styled.div`
|
||||
@@ -19,7 +19,7 @@ const Container = styled.div`
|
||||
width: 100%;
|
||||
animation: ${loadingFrame} 4s ease-in-out infinite;
|
||||
animation-delay: 250ms;
|
||||
margin-left: -100%;
|
||||
transform: translateX(-100%);
|
||||
`;
|
||||
|
||||
const Loader = styled.div`
|
||||
|
||||
@@ -47,120 +47,114 @@ type Props = {
|
||||
/** Callback when menu is closed */
|
||||
onClose?: () => void;
|
||||
// TODO: Invert the dependency chain by forwarding dropdown ref and props to Tooltip component
|
||||
ref?: React.Ref<React.ComponentRef<typeof TooltipPrimitive.Trigger>>;
|
||||
} & React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Trigger>;
|
||||
|
||||
export const DropdownMenu = observer(
|
||||
React.forwardRef<React.ElementRef<typeof TooltipPrimitive.Trigger>, Props>(
|
||||
(
|
||||
{
|
||||
action,
|
||||
children,
|
||||
align = "start",
|
||||
ariaLabel,
|
||||
modal = true,
|
||||
append,
|
||||
onOpen,
|
||||
onClose,
|
||||
...rest
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const isMobile = useMobile();
|
||||
const contentRef =
|
||||
React.useRef<React.ElementRef<typeof MenuContent>>(null);
|
||||
const actionContext = useActionContext({
|
||||
isMenu: true,
|
||||
});
|
||||
export const DropdownMenu = observer(function DropdownMenu({
|
||||
ref,
|
||||
action,
|
||||
children,
|
||||
align = "start",
|
||||
ariaLabel,
|
||||
modal = true,
|
||||
append,
|
||||
onOpen,
|
||||
onClose,
|
||||
...rest
|
||||
}: Props) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const isMobile = useMobile();
|
||||
const contentRef = React.useRef<React.ComponentRef<typeof MenuContent>>(null);
|
||||
const actionContext = useActionContext({
|
||||
isMenu: true,
|
||||
});
|
||||
|
||||
const menuItems = useComputed(() => {
|
||||
if (!open) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const resolvedAction = typeof action === "function" ? action() : action;
|
||||
|
||||
return (resolvedAction.children as ActionVariant[]).map((childAction) =>
|
||||
actionToMenuItem(childAction, actionContext)
|
||||
);
|
||||
}, [open, action, actionContext]);
|
||||
|
||||
// Only visibility is resolved while the menu is closed, the remainder of
|
||||
// each item is resolved when it is opened.
|
||||
const isEmpty = useComputed(() => {
|
||||
const resolvedAction = typeof action === "function" ? action() : action;
|
||||
|
||||
return !hasVisibleActions(
|
||||
resolvedAction.children as ActionVariant[],
|
||||
actionContext
|
||||
);
|
||||
}, [action, actionContext]);
|
||||
|
||||
const handleOpenChange = React.useCallback(
|
||||
(open: boolean) => {
|
||||
setOpen(open);
|
||||
if (open) {
|
||||
onOpen?.();
|
||||
} else {
|
||||
onClose?.();
|
||||
}
|
||||
},
|
||||
[onOpen, onClose]
|
||||
);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "auto";
|
||||
}
|
||||
}, []);
|
||||
|
||||
const disablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "none";
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (isEmpty && !append) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<MobileDropdown
|
||||
open={open}
|
||||
onOpenChange={handleOpenChange}
|
||||
items={menuItems}
|
||||
trigger={children}
|
||||
ariaLabel={ariaLabel}
|
||||
append={append}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const content = toMenuItems(menuItems);
|
||||
|
||||
return (
|
||||
<MenuProvider variant="dropdown">
|
||||
<Menu open={open} onOpenChange={handleOpenChange} modal={modal}>
|
||||
<MenuTrigger ref={ref} aria-label={ariaLabel} {...rest}>
|
||||
{children}
|
||||
</MenuTrigger>
|
||||
<MenuContent
|
||||
align={align}
|
||||
aria-label={ariaLabel}
|
||||
onAnimationStart={disablePointerEvents}
|
||||
onAnimationEnd={enablePointerEvents}
|
||||
onCloseAutoFocus={preventDefault}
|
||||
>
|
||||
{content}
|
||||
{append}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
</MenuProvider>
|
||||
);
|
||||
const menuItems = useComputed(() => {
|
||||
if (!open) {
|
||||
return [];
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
const resolvedAction = typeof action === "function" ? action() : action;
|
||||
|
||||
return (resolvedAction.children as ActionVariant[]).map((childAction) =>
|
||||
actionToMenuItem(childAction, actionContext)
|
||||
);
|
||||
}, [open, action, actionContext]);
|
||||
|
||||
// Only visibility is resolved while the menu is closed, the remainder of
|
||||
// each item is resolved when it is opened.
|
||||
const isEmpty = useComputed(() => {
|
||||
const resolvedAction = typeof action === "function" ? action() : action;
|
||||
|
||||
return !hasVisibleActions(
|
||||
resolvedAction.children as ActionVariant[],
|
||||
actionContext
|
||||
);
|
||||
}, [action, actionContext]);
|
||||
|
||||
const handleOpenChange = React.useCallback(
|
||||
(open: boolean) => {
|
||||
setOpen(open);
|
||||
if (open) {
|
||||
onOpen?.();
|
||||
} else {
|
||||
onClose?.();
|
||||
}
|
||||
},
|
||||
[onOpen, onClose]
|
||||
);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "auto";
|
||||
}
|
||||
}, []);
|
||||
|
||||
const disablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
contentRef.current.style.pointerEvents = "none";
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (isEmpty && !append) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<MobileDropdown
|
||||
open={open}
|
||||
onOpenChange={handleOpenChange}
|
||||
items={menuItems}
|
||||
trigger={children}
|
||||
ariaLabel={ariaLabel}
|
||||
append={append}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const content = toMenuItems(menuItems);
|
||||
|
||||
return (
|
||||
<MenuProvider variant="dropdown">
|
||||
<Menu open={open} onOpenChange={handleOpenChange} modal={modal}>
|
||||
<MenuTrigger ref={ref} aria-label={ariaLabel} {...rest}>
|
||||
{children}
|
||||
</MenuTrigger>
|
||||
<MenuContent
|
||||
align={align}
|
||||
aria-label={ariaLabel}
|
||||
onAnimationStart={disablePointerEvents}
|
||||
onAnimationEnd={enablePointerEvents}
|
||||
onCloseAutoFocus={preventDefault}
|
||||
>
|
||||
{content}
|
||||
{append}
|
||||
</MenuContent>
|
||||
</Menu>
|
||||
</MenuProvider>
|
||||
);
|
||||
});
|
||||
|
||||
type MobileDropdownProps = {
|
||||
open: boolean;
|
||||
@@ -178,7 +172,8 @@ function MobileDropdown({
|
||||
append,
|
||||
}: MobileDropdownProps) {
|
||||
const [submenuName, setSubmenuName] = React.useState<string>();
|
||||
const contentRef = React.useRef<React.ElementRef<typeof DrawerContent>>(null);
|
||||
const contentRef =
|
||||
React.useRef<React.ComponentRef<typeof DrawerContent>>(null);
|
||||
|
||||
const enablePointerEvents = React.useCallback(() => {
|
||||
if (contentRef.current) {
|
||||
|
||||
@@ -9,16 +9,20 @@ type Props = React.ComponentPropsWithoutRef<
|
||||
> & {
|
||||
neutral?: boolean;
|
||||
className?: string;
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
export const OverflowMenuButton = React.forwardRef<HTMLButtonElement, Props>(
|
||||
({ neutral, className, ...rest }, ref) =>
|
||||
neutral ? (
|
||||
<Button ref={ref} icon={<MoreIcon />} neutral borderOnHover {...rest} />
|
||||
) : (
|
||||
<NudeButton ref={ref} className={className} {...rest}>
|
||||
<MoreIcon />
|
||||
</NudeButton>
|
||||
)
|
||||
);
|
||||
OverflowMenuButton.displayName = "OverflowMenuButton";
|
||||
export function OverflowMenuButton({
|
||||
ref,
|
||||
neutral,
|
||||
className,
|
||||
...rest
|
||||
}: Props) {
|
||||
return neutral ? (
|
||||
<Button ref={ref} icon={<MoreIcon />} neutral borderOnHover {...rest} />
|
||||
) : (
|
||||
<NudeButton ref={ref} className={className} {...rest}>
|
||||
<MoreIcon />
|
||||
</NudeButton>
|
||||
);
|
||||
}
|
||||
@@ -18,12 +18,16 @@ type Props = Omit<React.ComponentProps<typeof NavLink>, "children"> & {
|
||||
activeStyle?: React.CSSProperties;
|
||||
/** The path to match against the current location */
|
||||
to: LocationDescriptor;
|
||||
ref?: React.Ref<HTMLAnchorElement>;
|
||||
};
|
||||
|
||||
function NavLinkWithChildrenFunc(
|
||||
{ to, exact = false, children, ...rest }: Props,
|
||||
ref?: React.Ref<HTMLAnchorElement>
|
||||
) {
|
||||
function NavLinkWithChildrenFunc({
|
||||
to,
|
||||
exact = false,
|
||||
children,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
return (
|
||||
<Route path={typeof to === "string" ? to : to?.pathname} exact={exact}>
|
||||
{({ match, location }) => (
|
||||
@@ -40,6 +44,4 @@ function NavLinkWithChildrenFunc(
|
||||
);
|
||||
}
|
||||
|
||||
export default React.forwardRef<HTMLAnchorElement, Props>(
|
||||
NavLinkWithChildrenFunc
|
||||
);
|
||||
export default NavLinkWithChildrenFunc;
|
||||
@@ -6,8 +6,8 @@ import Text from "./Text";
|
||||
|
||||
type Props = {
|
||||
children?: React.ReactNode;
|
||||
icon?: JSX.Element;
|
||||
description?: JSX.Element;
|
||||
icon?: React.JSX.Element;
|
||||
description?: React.JSX.Element;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
@@ -34,13 +34,14 @@ const Notice: React.FC<Props> = ({
|
||||
);
|
||||
|
||||
const Title = styled.span`
|
||||
color: ${s("textSecondary")};
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
`;
|
||||
|
||||
const Container = styled(Text)`
|
||||
background: ${s("sidebarBackground")};
|
||||
color: ${s("sidebarText")};
|
||||
color: ${s("textTertiary")};
|
||||
padding: 10px 12px;
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
|
||||
@@ -73,15 +73,14 @@ function useStableOrderedNotifications(
|
||||
type Props = {
|
||||
/** Callback when the notification panel wants to close. */
|
||||
onRequestClose: () => void;
|
||||
/** Ref to the scrollable container. */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
/**
|
||||
* A panel containing a list of notifications and controls to manage them.
|
||||
*/
|
||||
function Notifications(
|
||||
{ onRequestClose }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
function Notifications({ onRequestClose, ref }: Props) {
|
||||
const { notifications } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useMobile();
|
||||
@@ -222,4 +221,4 @@ const Header = styled(Flex)`
|
||||
}
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(Notifications));
|
||||
export default observer(Notifications);
|
||||
@@ -5,10 +5,15 @@ import { InputSelect } from "../InputSelect";
|
||||
/**
|
||||
* An input that allows a choice of OAuth client type.
|
||||
*/
|
||||
export const InputClientType = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
Omit<React.ComponentPropsWithoutRef<typeof InputSelect>, "options" | "label">
|
||||
>((props, ref) => {
|
||||
export function InputClientType({
|
||||
ref,
|
||||
...props
|
||||
}: Omit<
|
||||
React.ComponentPropsWithoutRef<typeof InputSelect>,
|
||||
"options" | "label"
|
||||
> & {
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<InputSelect
|
||||
@@ -32,4 +37,4 @@ export const InputClientType = React.forwardRef<
|
||||
]}
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -3,9 +3,10 @@ import * as React from "react";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
|
||||
type Props = React.ComponentProps<typeof OneTimePasswordRoot> & {
|
||||
type Props = React.ComponentPropsWithoutRef<typeof OneTimePasswordRoot> & {
|
||||
/** The length of the OTP */
|
||||
length?: number;
|
||||
ref?: React.Ref<HTMLInputElement>;
|
||||
/**
|
||||
* Whether to accept uppercase letters in addition to digits. Lowercase input
|
||||
* is normalized to uppercase. Defaults to numeric only.
|
||||
@@ -16,28 +17,28 @@ type Props = React.ComponentProps<typeof OneTimePasswordRoot> & {
|
||||
const sanitizeAlphanumeric = (value: string) =>
|
||||
value.replace(/[^a-zA-Z0-9]/g, "").toUpperCase();
|
||||
|
||||
export const OneTimePasswordInput = React.forwardRef(
|
||||
function OneTimePasswordInput_(
|
||||
{ length = 6, alphanumeric, ...rest }: Props,
|
||||
ref: React.RefObject<HTMLInputElement>
|
||||
) {
|
||||
const alphanumericProps = alphanumeric
|
||||
? {
|
||||
validationType: "none" as const,
|
||||
sanitizeValue: sanitizeAlphanumeric,
|
||||
}
|
||||
: undefined;
|
||||
export function OneTimePasswordInput({
|
||||
length = 6,
|
||||
alphanumeric,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
const alphanumericProps = alphanumeric
|
||||
? {
|
||||
validationType: "none" as const,
|
||||
sanitizeValue: sanitizeAlphanumeric,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<OneTimePasswordRoot {...alphanumericProps} {...rest}>
|
||||
{Array.from({ length }, (_, i) => (
|
||||
<OneTimePasswordInputField key={i} />
|
||||
))}
|
||||
<OneTimePasswordField.HiddenInput ref={ref} />
|
||||
</OneTimePasswordRoot>
|
||||
);
|
||||
}
|
||||
);
|
||||
return (
|
||||
<OneTimePasswordRoot {...alphanumericProps} {...rest}>
|
||||
{Array.from({ length }, (_, i) => (
|
||||
<OneTimePasswordInputField key={i} />
|
||||
))}
|
||||
<OneTimePasswordField.HiddenInput ref={ref} />
|
||||
</OneTimePasswordRoot>
|
||||
);
|
||||
}
|
||||
|
||||
const OneTimePasswordRoot = styled(OneTimePasswordField.Root)`
|
||||
display: flex;
|
||||
|
||||
@@ -1,15 +1,49 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { Helmet } from "react-helmet-async";
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useLayoutEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import type { ReactNode } from "react";
|
||||
import env from "~/env";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { useSplitView } from "./SplitView/context";
|
||||
import { useTeamContext } from "./TeamContext";
|
||||
|
||||
type FallbackProps = {
|
||||
/** The title to use while no descendant PageTitle is mounted. */
|
||||
title: string;
|
||||
children?: ReactNode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders a fallback document title that yields to any descendant PageTitle,
|
||||
* so that only a single title element is ever present in the head.
|
||||
*/
|
||||
export function FallbackPageTitle({ title, children }: FallbackProps) {
|
||||
const [claims, setClaims] = useState(0);
|
||||
const handleClaim = useCallback(() => {
|
||||
setClaims((count) => count + 1);
|
||||
return () => setClaims((count) => count - 1);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ClaimContext.Provider value={handleClaim}>
|
||||
{claims === 0 && <title>{title}</title>}
|
||||
{children}
|
||||
</ClaimContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
type Props = {
|
||||
title: string;
|
||||
favicon?: string;
|
||||
};
|
||||
|
||||
const ClaimContext = createContext<(() => () => void) | undefined>(undefined);
|
||||
|
||||
const originalShortcutHref = document
|
||||
.querySelector('link[rel="shortcut icon"]')
|
||||
?.getAttribute("href") as string;
|
||||
@@ -18,6 +52,12 @@ const PageTitle = ({ title, favicon }: Props) => {
|
||||
const { auth } = useStores();
|
||||
const team = useTeamContext() ?? auth.team;
|
||||
const { isFocused } = useSplitView();
|
||||
const claim = useContext(ClaimContext);
|
||||
|
||||
useLayoutEffect(
|
||||
() => (isFocused ? claim?.() : undefined),
|
||||
[claim, isFocused]
|
||||
);
|
||||
|
||||
// Only the focused pane of a split view titles the tab, otherwise the panes
|
||||
// compete and the title depends on which rendered last.
|
||||
@@ -26,7 +66,7 @@ const PageTitle = ({ title, favicon }: Props) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Helmet>
|
||||
<>
|
||||
<title>
|
||||
{team?.name ? `${title} - ${team.name}` : `${title} - ${env.APP_NAME}`}
|
||||
</title>
|
||||
@@ -36,7 +76,7 @@ const PageTitle = ({ title, favicon }: Props) => {
|
||||
href={favicon ?? originalShortcutHref}
|
||||
key={favicon ?? originalShortcutHref}
|
||||
/>
|
||||
</Helmet>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type Props = {
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
options?: Record<string, any>;
|
||||
heading?: React.ReactNode;
|
||||
empty?: JSX.Element;
|
||||
empty?: React.JSX.Element;
|
||||
showParentDocuments?: boolean;
|
||||
showCollection?: boolean;
|
||||
showPublished?: boolean;
|
||||
|
||||
@@ -48,10 +48,10 @@ interface Props<
|
||||
heading?: React.ReactNode;
|
||||
|
||||
/** Content to display when the list is empty */
|
||||
empty?: JSX.Element | null;
|
||||
empty?: React.JSX.Element | null;
|
||||
|
||||
/** Optional loading state content */
|
||||
loading?: JSX.Element | null;
|
||||
loading?: React.JSX.Element | null;
|
||||
|
||||
/** Array of items to display in the list */
|
||||
items?: T[];
|
||||
@@ -75,7 +75,7 @@ interface Props<
|
||||
error: Error;
|
||||
/** Function to retry the fetch operation */
|
||||
retry: () => void;
|
||||
}) => JSX.Element;
|
||||
}) => React.JSX.Element;
|
||||
|
||||
/**
|
||||
* Function to render section headings (typically date-based)
|
||||
@@ -96,7 +96,7 @@ interface Props<
|
||||
onEscape?: (ev: React.KeyboardEvent<HTMLDivElement>) => void;
|
||||
|
||||
/** Reference to the list container element */
|
||||
listRef?: React.RefObject<HTMLDivElement>;
|
||||
listRef?: React.RefObject<HTMLDivElement | null>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ const PaginatedList = <T extends PaginatedItem>({
|
||||
onEscape,
|
||||
listRef,
|
||||
...rest
|
||||
}: Props<T>): JSX.Element | null => {
|
||||
}: Props<T>): React.JSX.Element | null => {
|
||||
const user = useCurrentUser({ rejectOnEmpty: false });
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
@@ -82,8 +82,7 @@ function PinnedDocuments({
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor, {
|
||||
activationConstraint: {
|
||||
delay: 100,
|
||||
tolerance: 5,
|
||||
distance: 8,
|
||||
},
|
||||
}),
|
||||
useSensor(KeyboardSensor, {
|
||||
|
||||
@@ -15,41 +15,42 @@ type Props = {
|
||||
config?: TargetAndTransition;
|
||||
/** Optional styles. */
|
||||
style?: React.CSSProperties;
|
||||
/** Ref to the inner content element. */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically animates the height of a container based on it's contents.
|
||||
*/
|
||||
export const ResizingHeightContainer = React.forwardRef<HTMLDivElement, Props>(
|
||||
function ResizingHeightContainer_(props, forwardedRef) {
|
||||
const {
|
||||
hideOverflow,
|
||||
children,
|
||||
config = {
|
||||
transition: {
|
||||
duration: 0.1,
|
||||
ease: "easeInOut",
|
||||
},
|
||||
export function ResizingHeightContainer(props: Props) {
|
||||
const {
|
||||
hideOverflow,
|
||||
children,
|
||||
config = {
|
||||
transition: {
|
||||
duration: 0.1,
|
||||
ease: "easeInOut",
|
||||
},
|
||||
style,
|
||||
} = props;
|
||||
},
|
||||
style,
|
||||
ref: forwardedRef,
|
||||
} = props;
|
||||
|
||||
const [measureRef, { height }] = useMeasure();
|
||||
const [measureRef, { height }] = useMeasure();
|
||||
|
||||
return (
|
||||
<m.div
|
||||
animate={{
|
||||
...config,
|
||||
height: Math.round(height),
|
||||
}}
|
||||
style={{
|
||||
...style,
|
||||
overflow: hideOverflow ? "hidden" : "inherit",
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
<div ref={mergeRefs([measureRef, forwardedRef])}>{children}</div>
|
||||
</m.div>
|
||||
);
|
||||
}
|
||||
);
|
||||
return (
|
||||
<m.div
|
||||
animate={{
|
||||
...config,
|
||||
height: Math.round(height),
|
||||
}}
|
||||
style={{
|
||||
...style,
|
||||
overflow: hideOverflow ? "hidden" : "inherit",
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
<div ref={mergeRefs([measureRef, forwardedRef])}>{children}</div>
|
||||
</m.div>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { createContext, useContext } from "react";
|
||||
* Context to provide a reference to the scrollable container
|
||||
*/
|
||||
const ScrollContext = createContext<
|
||||
React.RefObject<HTMLDivElement> | undefined
|
||||
React.RefObject<HTMLDivElement | null> | undefined
|
||||
>(undefined);
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ import usePrevious from "~/hooks/usePrevious";
|
||||
import { useScrollContext } from "./ScrollContext";
|
||||
|
||||
type Props = {
|
||||
children: JSX.Element;
|
||||
children: React.JSX.Element;
|
||||
};
|
||||
|
||||
export default function ScrollToTop({ children }: Props) {
|
||||
|
||||
@@ -19,29 +19,28 @@ type Props = React.HTMLAttributes<HTMLDivElement> & {
|
||||
flex?: boolean;
|
||||
/** Custom overflow style */
|
||||
overflow?: string;
|
||||
/** Ref to the scrollable div element */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
/**
|
||||
* A scrollable container component with optional shadow indicators and custom scrollbar styling.
|
||||
*
|
||||
* @param props - component properties.
|
||||
* @param ref - forwarded ref to the scrollable div element.
|
||||
* @returns the scrollable container element.
|
||||
*/
|
||||
function Scrollable(
|
||||
{
|
||||
shadow,
|
||||
topShadow,
|
||||
bottomShadow,
|
||||
hiddenScrollbars,
|
||||
fadeTo,
|
||||
flex,
|
||||
overflow,
|
||||
children,
|
||||
...rest
|
||||
}: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
function Scrollable({
|
||||
shadow,
|
||||
topShadow,
|
||||
bottomShadow,
|
||||
hiddenScrollbars,
|
||||
fadeTo,
|
||||
flex,
|
||||
overflow,
|
||||
children,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
const localRef = React.useRef<HTMLDivElement>(null);
|
||||
const [topShadowVisible, setTopShadow] = React.useState(false);
|
||||
const [bottomShadowVisible, setBottomShadow] = React.useState(false);
|
||||
@@ -172,4 +171,4 @@ const Wrapper = styled.div<{
|
||||
${(props) => props.$hiddenScrollbars && hideScrollbars()}
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(Scrollable));
|
||||
export default observer(Scrollable);
|
||||
@@ -31,12 +31,11 @@ type Props = {
|
||||
collection: Collection;
|
||||
/** The existing share model, if any. */
|
||||
share: Share | null | undefined;
|
||||
/** Ref to the container element. */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
function InnerPublicAccess(
|
||||
{ collection, share }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
function InnerPublicAccess({ collection, share, ref }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { shares } = useStores();
|
||||
const theme = useTheme();
|
||||
@@ -185,4 +184,4 @@ function InnerPublicAccess(
|
||||
);
|
||||
}
|
||||
|
||||
export const PublicAccess = observer(React.forwardRef(InnerPublicAccess));
|
||||
export const PublicAccess = observer(InnerPublicAccess);
|
||||
@@ -41,12 +41,11 @@ type Props = {
|
||||
/** Ref to the Copy Link button */
|
||||
copyButtonRef?: React.RefObject<HTMLButtonElement>;
|
||||
onRequestClose?: () => void;
|
||||
/** Ref to the container element. */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
function PublicAccess(
|
||||
{ document, share, sharedParent }: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
function PublicAccess({ document, share, sharedParent, ref }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { shares } = useStores();
|
||||
const theme = useTheme();
|
||||
@@ -234,4 +233,4 @@ function PublicAccess(
|
||||
);
|
||||
}
|
||||
|
||||
export default observer(React.forwardRef(PublicAccess));
|
||||
export default observer(PublicAccess);
|
||||
@@ -14,7 +14,7 @@ export function CopyLinkButton({
|
||||
onCopy: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const timeout = useRef<ReturnType<typeof setTimeout>>();
|
||||
const timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
|
||||
const handleCopied = useCallback(() => {
|
||||
onCopy();
|
||||
|
||||
@@ -14,12 +14,18 @@ type Props = {
|
||||
onKeyDown: React.KeyboardEventHandler;
|
||||
back: React.ReactNode;
|
||||
action: React.ReactNode;
|
||||
ref?: React.Ref<HTMLInputElement>;
|
||||
};
|
||||
|
||||
export const SearchInput = React.forwardRef(function SearchInput_(
|
||||
{ onChange, onClick, onKeyDown, query, back, action }: Props,
|
||||
ref: React.Ref<HTMLInputElement>
|
||||
) {
|
||||
export function SearchInput({
|
||||
onChange,
|
||||
onClick,
|
||||
onKeyDown,
|
||||
query,
|
||||
back,
|
||||
action,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const inputRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
@@ -72,4 +78,4 @@ export const SearchInput = React.forwardRef(function SearchInput_(
|
||||
</AnimatePresence>
|
||||
</HeaderInput>
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -44,218 +44,216 @@ type Props = {
|
||||
removePendingId: (id: string) => void;
|
||||
/** Handles escape from suggestions list */
|
||||
onEscape?: (ev: React.KeyboardEvent<HTMLDivElement>) => void;
|
||||
/** Ref to the keyboard navigation container. */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
export const Suggestions = observer(
|
||||
React.forwardRef(function Suggestions_(
|
||||
export const Suggestions = observer(function Suggestions({
|
||||
document,
|
||||
collection,
|
||||
query,
|
||||
pendingIds,
|
||||
addPendingId,
|
||||
removePendingId,
|
||||
onEscape,
|
||||
ref,
|
||||
}: Props) {
|
||||
const neverRenderedList = React.useRef(false);
|
||||
const { users, groups } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const user = useCurrentUser();
|
||||
const containerRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const { maxHeight } = useMaxHeight({
|
||||
elementRef: containerRef,
|
||||
maxViewportPercentage: 70,
|
||||
});
|
||||
|
||||
const fetchUsersByQuery = useThrottledCallback(
|
||||
(searchQuery: string) => {
|
||||
void users.fetchPage({ query: searchQuery });
|
||||
void groups.fetchPage({ query: searchQuery });
|
||||
},
|
||||
250,
|
||||
undefined,
|
||||
{
|
||||
document,
|
||||
collection,
|
||||
query,
|
||||
pendingIds,
|
||||
addPendingId,
|
||||
removePendingId,
|
||||
onEscape,
|
||||
}: Props,
|
||||
ref: React.Ref<HTMLDivElement>
|
||||
) {
|
||||
const neverRenderedList = React.useRef(false);
|
||||
const { users, groups } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const user = useCurrentUser();
|
||||
const containerRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const { maxHeight } = useMaxHeight({
|
||||
elementRef: containerRef,
|
||||
maxViewportPercentage: 70,
|
||||
});
|
||||
leading: true,
|
||||
}
|
||||
);
|
||||
|
||||
const fetchUsersByQuery = useThrottledCallback(
|
||||
(searchQuery: string) => {
|
||||
void users.fetchPage({ query: searchQuery });
|
||||
void groups.fetchPage({ query: searchQuery });
|
||||
},
|
||||
250,
|
||||
undefined,
|
||||
{
|
||||
leading: true,
|
||||
}
|
||||
);
|
||||
const getSuggestionForEmail = React.useCallback(
|
||||
(email: string) => ({
|
||||
id: email,
|
||||
name: email,
|
||||
avatarUrl: "",
|
||||
color: stringToColor(email),
|
||||
initial: email[0].toUpperCase(),
|
||||
email: t("Invite to workspace"),
|
||||
}),
|
||||
[t]
|
||||
);
|
||||
|
||||
const getSuggestionForEmail = React.useCallback(
|
||||
(email: string) => ({
|
||||
id: email,
|
||||
name: email,
|
||||
avatarUrl: "",
|
||||
color: stringToColor(email),
|
||||
initial: email[0].toUpperCase(),
|
||||
email: t("Invite to workspace"),
|
||||
}),
|
||||
[t]
|
||||
);
|
||||
const suggestions = React.useMemo(() => {
|
||||
const filtered: Suggestion[] = (
|
||||
document
|
||||
? users
|
||||
.notInDocument(document.id, query)
|
||||
.filter((u) => u.id !== user.id)
|
||||
: collection
|
||||
? users.notInCollection(collection.id, query)
|
||||
: users.activeOrInvited
|
||||
).filter((u) => !u.isSuspended);
|
||||
|
||||
const suggestions = React.useMemo(() => {
|
||||
const filtered: Suggestion[] = (
|
||||
document
|
||||
? users
|
||||
.notInDocument(document.id, query)
|
||||
.filter((u) => u.id !== user.id)
|
||||
: collection
|
||||
? users.notInCollection(collection.id, query)
|
||||
: users.activeOrInvited
|
||||
).filter((u) => !u.isSuspended);
|
||||
if (isEmail(query) && !users.getByEmail(query)) {
|
||||
filtered.push(getSuggestionForEmail(query));
|
||||
}
|
||||
|
||||
if (isEmail(query) && !users.getByEmail(query)) {
|
||||
filtered.push(getSuggestionForEmail(query));
|
||||
}
|
||||
return [
|
||||
...(document
|
||||
? groups.notInDocument(document.id, query)
|
||||
: collection
|
||||
? groups.notInCollection(collection.id, query)
|
||||
: []),
|
||||
...filtered,
|
||||
];
|
||||
// The store collections listed below are observable dependencies, they
|
||||
// are what recompute the suggestions when the underlying data changes.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
getSuggestionForEmail,
|
||||
users,
|
||||
users.activeOrInvited,
|
||||
groups,
|
||||
groups.orderedData,
|
||||
document?.id,
|
||||
document?.members,
|
||||
collection?.id,
|
||||
user.id,
|
||||
query,
|
||||
t,
|
||||
]);
|
||||
|
||||
return [
|
||||
...(document
|
||||
? groups.notInDocument(document.id, query)
|
||||
: collection
|
||||
? groups.notInCollection(collection.id, query)
|
||||
: []),
|
||||
...filtered,
|
||||
];
|
||||
// The store collections listed below are observable dependencies, they
|
||||
// are what recompute the suggestions when the underlying data changes.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
getSuggestionForEmail,
|
||||
users,
|
||||
users.activeOrInvited,
|
||||
groups,
|
||||
groups.orderedData,
|
||||
document?.id,
|
||||
document?.members,
|
||||
collection?.id,
|
||||
user.id,
|
||||
query,
|
||||
t,
|
||||
]);
|
||||
const pending = React.useMemo(
|
||||
() =>
|
||||
pendingIds
|
||||
.map((id) =>
|
||||
isEmail(id)
|
||||
? getSuggestionForEmail(id)
|
||||
: (users.get(id) ?? groups.get(id))
|
||||
)
|
||||
.filter(Boolean) as User[],
|
||||
[users, groups, getSuggestionForEmail, pendingIds]
|
||||
);
|
||||
|
||||
const pending = React.useMemo(
|
||||
() =>
|
||||
pendingIds
|
||||
.map((id) =>
|
||||
isEmail(id)
|
||||
? getSuggestionForEmail(id)
|
||||
: (users.get(id) ?? groups.get(id))
|
||||
)
|
||||
.filter(Boolean) as User[],
|
||||
[users, groups, getSuggestionForEmail, pendingIds]
|
||||
);
|
||||
React.useEffect(() => {
|
||||
fetchUsersByQuery(query);
|
||||
}, [query, fetchUsersByQuery]);
|
||||
|
||||
React.useEffect(() => {
|
||||
fetchUsersByQuery(query);
|
||||
}, [query, fetchUsersByQuery]);
|
||||
|
||||
function getListItemProps(suggestion: User | Group) {
|
||||
if (suggestion instanceof Group) {
|
||||
return {
|
||||
title: suggestion.name,
|
||||
subtitle: (
|
||||
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
|
||||
<span onClick={(ev) => ev.stopPropagation()}>
|
||||
<GroupMembersPopover group={suggestion}>
|
||||
<StyledButtonLink>
|
||||
{t("{{ count }} member", {
|
||||
count: suggestion.memberCount,
|
||||
})}
|
||||
</StyledButtonLink>
|
||||
</GroupMembersPopover>
|
||||
</span>
|
||||
),
|
||||
image: <GroupAvatar group={suggestion} />,
|
||||
};
|
||||
}
|
||||
function getListItemProps(suggestion: User | Group) {
|
||||
if (suggestion instanceof Group) {
|
||||
return {
|
||||
title: suggestion.name,
|
||||
subtitle: suggestion.email
|
||||
? suggestion.email
|
||||
: suggestion.isViewer
|
||||
? t("Viewer")
|
||||
: t("Editor"),
|
||||
image: <Avatar model={suggestion} size={AvatarSize.Medium} />,
|
||||
subtitle: (
|
||||
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
|
||||
<span onClick={(ev) => ev.stopPropagation()}>
|
||||
<GroupMembersPopover group={suggestion}>
|
||||
<StyledButtonLink>
|
||||
{t("{{ count }} member", {
|
||||
count: suggestion.memberCount,
|
||||
})}
|
||||
</StyledButtonLink>
|
||||
</GroupMembersPopover>
|
||||
</span>
|
||||
),
|
||||
image: <GroupAvatar group={suggestion} />,
|
||||
};
|
||||
}
|
||||
return {
|
||||
title: suggestion.name,
|
||||
subtitle: suggestion.email
|
||||
? suggestion.email
|
||||
: suggestion.isViewer
|
||||
? t("Viewer")
|
||||
: t("Editor"),
|
||||
image: <Avatar model={suggestion} size={AvatarSize.Medium} />,
|
||||
};
|
||||
}
|
||||
|
||||
const isEmpty = suggestions.length === 0;
|
||||
const pendingIdSet = new Set(pendingIds);
|
||||
const suggestionsWithPending = suggestions.filter(
|
||||
(u) => !pendingIdSet.has(u.id)
|
||||
);
|
||||
const isEmpty = suggestions.length === 0;
|
||||
const pendingIdSet = new Set(pendingIds);
|
||||
const suggestionsWithPending = suggestions.filter(
|
||||
(u) => !pendingIdSet.has(u.id)
|
||||
);
|
||||
|
||||
if (users.isFetching && isEmpty && neverRenderedList.current) {
|
||||
return <Placeholder />;
|
||||
}
|
||||
if (users.isFetching && isEmpty && neverRenderedList.current) {
|
||||
return <Placeholder />;
|
||||
}
|
||||
|
||||
neverRenderedList.current = false;
|
||||
neverRenderedList.current = false;
|
||||
|
||||
return (
|
||||
<ScrollableContainer
|
||||
ref={containerRef}
|
||||
hiddenScrollbars
|
||||
style={{ maxHeight }}
|
||||
return (
|
||||
<ScrollableContainer
|
||||
ref={containerRef}
|
||||
hiddenScrollbars
|
||||
style={{ maxHeight }}
|
||||
>
|
||||
<ArrowKeyNavigation
|
||||
ref={ref}
|
||||
onEscape={onEscape}
|
||||
aria-label={t("Suggestions for invitation")}
|
||||
items={concat(pending, suggestionsWithPending)}
|
||||
>
|
||||
<ArrowKeyNavigation
|
||||
ref={ref}
|
||||
onEscape={onEscape}
|
||||
aria-label={t("Suggestions for invitation")}
|
||||
items={concat(pending, suggestionsWithPending)}
|
||||
>
|
||||
{() => [
|
||||
...pending.map((suggestion) => (
|
||||
<PendingListItem
|
||||
keyboardNavigation
|
||||
key={suggestion.id}
|
||||
{...getListItemProps(suggestion)}
|
||||
onClick={() => removePendingId(suggestion.id)}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === "Enter") {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
removePendingId(suggestion.id);
|
||||
}
|
||||
}}
|
||||
actions={
|
||||
<>
|
||||
<InvitedIcon />
|
||||
<RemoveIcon />
|
||||
</>
|
||||
{() => [
|
||||
...pending.map((suggestion) => (
|
||||
<PendingListItem
|
||||
keyboardNavigation
|
||||
key={suggestion.id}
|
||||
{...getListItemProps(suggestion)}
|
||||
onClick={() => removePendingId(suggestion.id)}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === "Enter") {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
removePendingId(suggestion.id);
|
||||
}
|
||||
/>
|
||||
)),
|
||||
pending.length > 0 &&
|
||||
(suggestionsWithPending.length > 0 || isEmpty) && (
|
||||
<Separator key="separator" />
|
||||
),
|
||||
...suggestionsWithPending.map((suggestion) => (
|
||||
<ListItem
|
||||
keyboardNavigation
|
||||
key={suggestion.id}
|
||||
{...getListItemProps(suggestion as User)}
|
||||
onClick={() => addPendingId(suggestion.id)}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === "Enter") {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
addPendingId(suggestion.id);
|
||||
}
|
||||
}}
|
||||
actions={<InviteIcon />}
|
||||
/>
|
||||
)),
|
||||
isEmpty && (
|
||||
<Empty key="empty" style={{ marginTop: 22 }}>
|
||||
{t("No matches")}
|
||||
</Empty>
|
||||
}}
|
||||
actions={
|
||||
<>
|
||||
<InvitedIcon />
|
||||
<RemoveIcon />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
)),
|
||||
pending.length > 0 &&
|
||||
(suggestionsWithPending.length > 0 || isEmpty) && (
|
||||
<Separator key="separator" />
|
||||
),
|
||||
]}
|
||||
</ArrowKeyNavigation>
|
||||
</ScrollableContainer>
|
||||
);
|
||||
})
|
||||
);
|
||||
...suggestionsWithPending.map((suggestion) => (
|
||||
<ListItem
|
||||
keyboardNavigation
|
||||
key={suggestion.id}
|
||||
{...getListItemProps(suggestion as User)}
|
||||
onClick={() => addPendingId(suggestion.id)}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === "Enter") {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
addPendingId(suggestion.id);
|
||||
}
|
||||
}}
|
||||
actions={<InviteIcon />}
|
||||
/>
|
||||
)),
|
||||
isEmpty && (
|
||||
<Empty key="empty" style={{ marginTop: 22 }}>
|
||||
{t("No matches")}
|
||||
</Empty>
|
||||
),
|
||||
]}
|
||||
</ArrowKeyNavigation>
|
||||
</ScrollableContainer>
|
||||
);
|
||||
});
|
||||
|
||||
const InvitedIcon = styled(CheckmarkIcon)`
|
||||
color: ${s("accent")};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Transition } from "framer-motion";
|
||||
import styled from "styled-components";
|
||||
import Flex from "@shared/components/Flex";
|
||||
import { s, hover } from "@shared/styles";
|
||||
@@ -92,7 +93,7 @@ export const presence = {
|
||||
type: "spring",
|
||||
duration: 0.2,
|
||||
bounce: 0,
|
||||
},
|
||||
} satisfies Transition,
|
||||
},
|
||||
exit: {
|
||||
opacity: 0,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Transition } from "framer-motion";
|
||||
import { m } from "framer-motion";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
@@ -80,7 +81,7 @@ function Aside({ children, border, className, skipInitialAnimation }: Props) {
|
||||
|
||||
// Resizing tracks the pointer exactly, otherwise width changes spring – which also animates the
|
||||
// snap back to the maximum or minimum when released from a stretched position.
|
||||
const transition = isResizing
|
||||
const transition: Transition = isResizing
|
||||
? { duration: 0 }
|
||||
: {
|
||||
type: "spring",
|
||||
|
||||
@@ -39,18 +39,18 @@ type Props = {
|
||||
className?: string;
|
||||
/** Content to render inside the sidebar. */
|
||||
children: React.ReactNode;
|
||||
/** Ref to the sidebar container. */
|
||||
ref?: React.Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
const Sidebar = React.forwardRef<HTMLDivElement, Props>(function Sidebar_(
|
||||
{
|
||||
children,
|
||||
hidden = false,
|
||||
canCollapse = true,
|
||||
showAccountMenu = true,
|
||||
className,
|
||||
}: Props,
|
||||
ref: React.RefObject<HTMLDivElement>
|
||||
) {
|
||||
function Sidebar({
|
||||
children,
|
||||
hidden = false,
|
||||
canCollapse = true,
|
||||
showAccountMenu = true,
|
||||
className,
|
||||
ref,
|
||||
}: Props) {
|
||||
const [isCollapsing, setCollapsing] = React.useState(false);
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
@@ -322,7 +322,7 @@ const Sidebar = React.forwardRef<HTMLDivElement, Props>(function Sidebar_(
|
||||
{ui.mobileSidebarVisible && <Backdrop onClick={handleCloseSidebar} />}
|
||||
</TooltipProvider>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const Backdrop = styled.a`
|
||||
animation: ${fadeIn} 250ms ease-in-out;
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { Location, LocationDescriptor } from "history";
|
||||
import { observer } from "mobx-react";
|
||||
import { PlusIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import type { ConnectDropTarget } from "react-dnd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { mergeRefs } from "react-merge-refs";
|
||||
import type { match } from "react-router";
|
||||
@@ -78,7 +77,7 @@ export type CollectionRowProps = {
|
||||
/** Ref forwarded to the outer Relative; for drag hover timers. */
|
||||
parentRef?: React.Ref<HTMLDivElement>;
|
||||
/** Drop target connector for "change collection" / reorder. */
|
||||
dropRef?: ConnectDropTarget;
|
||||
dropRef?: React.Ref<HTMLDivElement>;
|
||||
/** Whether the row is an active drop target (visual highlight). */
|
||||
isActiveDropTarget?: boolean;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import fractionalIndex from "fractional-index";
|
||||
import { observer } from "mobx-react";
|
||||
import { useMemo } from "react";
|
||||
import { useDrop } from "react-dnd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import type Collection from "~/models/Collection";
|
||||
@@ -10,7 +9,7 @@ import Error from "~/components/List/Error";
|
||||
import PaginatedList from "~/components/PaginatedList";
|
||||
import { createCollection } from "~/actions/definitions/collections";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import type { DragObject } from "../hooks/useDragAndDrop";
|
||||
import { type DragObject, useDropRef } from "../hooks/useDragAndDrop";
|
||||
import DraggableCollectionLink from "./DraggableCollectionLink";
|
||||
import DropCursor from "./DropCursor";
|
||||
import Header from "./Header";
|
||||
@@ -22,6 +21,8 @@ import SidebarLink from "./SidebarLink";
|
||||
import Text from "@shared/components/Text";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
|
||||
const headerActions = [createCollection];
|
||||
|
||||
function Collections() {
|
||||
const { documents, auth, collections, policies } = useStores();
|
||||
const { t } = useTranslation();
|
||||
@@ -38,7 +39,7 @@ function Collections() {
|
||||
const [
|
||||
{ isCollectionDropping, isDraggingAnyCollection },
|
||||
dropToReorderCollection,
|
||||
] = useDrop({
|
||||
] = useDropRef({
|
||||
accept: "collection",
|
||||
drop: async (item: DragObject) => {
|
||||
void collections.move(
|
||||
@@ -58,7 +59,12 @@ function Collections() {
|
||||
return (
|
||||
<SidebarContext.Provider value="collections">
|
||||
<Flex column>
|
||||
<Header id="collections" title={t("Collections")}>
|
||||
<Header
|
||||
id="collections"
|
||||
title={t("Collections")}
|
||||
actions={headerActions}
|
||||
primaryAction={createCollection}
|
||||
>
|
||||
<Relative>
|
||||
<PaginatedList<Collection>
|
||||
options={params}
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { Location, LocationDescriptor } from "history";
|
||||
import { observer } from "mobx-react";
|
||||
import { PlusIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import type { ConnectDragSource } from "react-dnd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { match } from "react-router";
|
||||
import styled from "styled-components";
|
||||
@@ -67,7 +66,7 @@ export type DocumentRowProps = {
|
||||
onCollapse?: () => void;
|
||||
|
||||
/** Drag source ref from the container's drag hook. */
|
||||
dragRef?: ConnectDragSource;
|
||||
dragRef?: React.RefCallback<HTMLElement>;
|
||||
/** Whether the row is being dragged. */
|
||||
isDragging?: boolean;
|
||||
/** Whether the row's document is being moved. */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as React from "react";
|
||||
import type { XYCoord } from "react-dnd";
|
||||
import { useDragLayer } from "react-dnd";
|
||||
import { NativeTypes } from "react-dnd-html5-backend";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -16,6 +17,10 @@ const layerStyles: React.CSSProperties = {
|
||||
height: "100%",
|
||||
};
|
||||
|
||||
// Browser-native drags (files, text, or ProseMirror nodes leaving the editor)
|
||||
// are tracked by react-dnd too, but they are not sidebar items.
|
||||
const nativeItemTypes = new Set<string | symbol>(Object.values(NativeTypes));
|
||||
|
||||
// Keep the ghost beside the pointer so it never covers the drop cursor.
|
||||
const POINTER_OFFSET_X = 12;
|
||||
const POINTER_OFFSET_Y = 14;
|
||||
@@ -41,14 +46,21 @@ const DragPlaceholder = () => {
|
||||
const { t } = useTranslation();
|
||||
const { ui } = useStores();
|
||||
|
||||
const { isDragging, item, pointerOffset } = useDragLayer((monitor) => ({
|
||||
item: monitor.getItem(),
|
||||
itemType: monitor.getItemType(),
|
||||
pointerOffset: monitor.getClientOffset(),
|
||||
isDragging: monitor.isDragging(),
|
||||
}));
|
||||
const { isDragging, item, itemType, pointerOffset } = useDragLayer(
|
||||
(monitor) => ({
|
||||
item: monitor.getItem(),
|
||||
itemType: monitor.getItemType(),
|
||||
pointerOffset: monitor.getClientOffset(),
|
||||
isDragging: monitor.isDragging(),
|
||||
})
|
||||
);
|
||||
|
||||
if (!isDragging || !pointerOffset) {
|
||||
if (
|
||||
!isDragging ||
|
||||
!pointerOffset ||
|
||||
!itemType ||
|
||||
nativeItemTypes.has(itemType)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ import fractionalIndex from "fractional-index";
|
||||
import { observer } from "mobx-react";
|
||||
import type * as React from "react";
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import type { DropTargetMonitor } from "react-dnd";
|
||||
import { useDrop, useDrag } from "react-dnd";
|
||||
import { getEmptyImage } from "react-dnd-html5-backend";
|
||||
import styled from "styled-components";
|
||||
import type Collection from "~/models/Collection";
|
||||
@@ -11,7 +9,7 @@ import type Document from "~/models/Document";
|
||||
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
||||
import { useActiveSidebarContext } from "~/hooks/useActiveSidebarContext";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import type { DragObject } from "../hooks/useDragAndDrop";
|
||||
import { useDragRef, useDropRef } from "../hooks/useDragAndDrop";
|
||||
import CollectionLink from "./CollectionLink";
|
||||
import DropCursor from "./DropCursor";
|
||||
import SidebarDisclosureContext, {
|
||||
@@ -26,6 +24,12 @@ type Props = {
|
||||
belowCollection: Collection | void;
|
||||
};
|
||||
|
||||
interface CollectionDragItem {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: React.ReactNode;
|
||||
}
|
||||
|
||||
function DraggableCollectionLink({
|
||||
collection,
|
||||
activeDocument,
|
||||
@@ -48,9 +52,13 @@ function DraggableCollectionLink({
|
||||
const [
|
||||
{ isCollectionDropping, isDraggingAnyCollection },
|
||||
dropToReorderCollection,
|
||||
] = useDrop({
|
||||
] = useDropRef<
|
||||
CollectionDragItem,
|
||||
void,
|
||||
{ isCollectionDropping: boolean; isDraggingAnyCollection: boolean }
|
||||
>({
|
||||
accept: "collection",
|
||||
drop: (item: DragObject) => {
|
||||
drop: (item) => {
|
||||
void collections.move(
|
||||
item.id,
|
||||
fractionalIndex(collection.index, belowCollectionIndex)
|
||||
@@ -60,14 +68,14 @@ function DraggableCollectionLink({
|
||||
collection.id !== item.id &&
|
||||
(!belowCollection || item.id !== belowCollection.id) &&
|
||||
!!policies.abilities(item.id).move,
|
||||
collect: (monitor: DropTargetMonitor<Collection, Collection>) => ({
|
||||
collect: (monitor) => ({
|
||||
isCollectionDropping: monitor.isOver(),
|
||||
isDraggingAnyCollection: monitor.canDrop(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Drag to reorder collection
|
||||
const [{ isDragging }, dragToReorderCollection, preview] = useDrag({
|
||||
const [{ isDragging }, dragToReorderCollection, preview] = useDragRef({
|
||||
type: "collection",
|
||||
item: () => ({
|
||||
id: collection.id,
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { createContext, useEffect, useState, type ReactNode } from "react";
|
||||
import type { ConnectDragSource } from "react-dnd";
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
type ReactNode,
|
||||
type RefCallback,
|
||||
} from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { SidebarSection, UserPreference } from "@shared/types";
|
||||
import { createAction } from "~/actions";
|
||||
import { NavigationSection } from "~/actions/sections";
|
||||
import { ArrowDownIcon, ArrowUpIcon } from "~/components/Icons/ArrowIcon";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import type { Action } from "~/types";
|
||||
import {
|
||||
useDragSidebarSection,
|
||||
useDropToReorderSidebarSection,
|
||||
@@ -12,11 +23,19 @@ import {
|
||||
import DropCursor from "./DropCursor";
|
||||
import Section from "./Section";
|
||||
|
||||
type SidebarSectionContextValue = {
|
||||
/** Drag connector so the section header can register as the drag handle. */
|
||||
dragRef: RefCallback<HTMLElement>;
|
||||
/** Actions offered in the section header's context menu. */
|
||||
menuActions: Action[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Carries the drag connector for a sidebar section so the section header can
|
||||
* register itself as the drag handle.
|
||||
* Carries the drag connector and the context menu actions for a sidebar
|
||||
* section to its header.
|
||||
*/
|
||||
export const SectionDragContext = createContext<ConnectDragSource | null>(null);
|
||||
export const SidebarSectionContext =
|
||||
createContext<SidebarSectionContextValue | null>(null);
|
||||
|
||||
/**
|
||||
* Normalizes a persisted sidebar section order — unknown values and
|
||||
@@ -64,6 +83,16 @@ export function moveSidebarSection(
|
||||
return result.every((s, i) => s === order[i]) ? undefined : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for sidebar section identifiers.
|
||||
*
|
||||
* @param value The value to check.
|
||||
* @returns true if the value names a sidebar section.
|
||||
*/
|
||||
function isSidebarSection(value: string): value is SidebarSection {
|
||||
return Object.values<string>(SidebarSection).includes(value);
|
||||
}
|
||||
|
||||
type Props = {
|
||||
/** The section being rendered. */
|
||||
section: SidebarSection;
|
||||
@@ -90,6 +119,82 @@ function DraggableSection({ section, children }: Props) {
|
||||
user.getPreference(UserPreference.SidebarSectionOrder, [])
|
||||
);
|
||||
|
||||
const [wrapper, setWrapper] = useState<HTMLDivElement | null>(null);
|
||||
|
||||
// Hidden sections are collapsed with CSS, so the nearest visible neighbour
|
||||
// is read from the DOM rather than from the persisted order.
|
||||
const findVisibleSibling = useCallback(
|
||||
(direction: "previous" | "next"): SidebarSection | undefined => {
|
||||
let element =
|
||||
direction === "previous"
|
||||
? wrapper?.previousElementSibling
|
||||
: wrapper?.nextElementSibling;
|
||||
|
||||
while (element instanceof HTMLElement) {
|
||||
const sibling = element.dataset.section;
|
||||
if (
|
||||
sibling &&
|
||||
isSidebarSection(sibling) &&
|
||||
getComputedStyle(element).display !== "none"
|
||||
) {
|
||||
return sibling;
|
||||
}
|
||||
element =
|
||||
direction === "previous"
|
||||
? element.previousElementSibling
|
||||
: element.nextElementSibling;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
[wrapper]
|
||||
);
|
||||
|
||||
const handleMove = useCallback(
|
||||
(direction: "previous" | "next") => {
|
||||
const target = findVisibleSibling(direction);
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newOrder = moveSidebarSection(
|
||||
normalizeSidebarSectionOrder(
|
||||
user.getPreference(UserPreference.SidebarSectionOrder, [])
|
||||
),
|
||||
section,
|
||||
direction === "previous" ? "before" : "after",
|
||||
target
|
||||
);
|
||||
if (newOrder) {
|
||||
user.setPreference(UserPreference.SidebarSectionOrder, newOrder);
|
||||
void user.save();
|
||||
}
|
||||
},
|
||||
[findVisibleSibling, section, user]
|
||||
);
|
||||
|
||||
const menuActions = useMemo(
|
||||
() => [
|
||||
createAction({
|
||||
name: ({ t }) => t("Move up"),
|
||||
analyticsName: "Move sidebar section up",
|
||||
section: NavigationSection,
|
||||
icon: <ArrowUpIcon />,
|
||||
visible: () => !!findVisibleSibling("previous"),
|
||||
perform: () => handleMove("previous"),
|
||||
}),
|
||||
createAction({
|
||||
name: ({ t }) => t("Move down"),
|
||||
analyticsName: "Move sidebar section down",
|
||||
section: NavigationSection,
|
||||
icon: <ArrowDownIcon />,
|
||||
visible: () => !!findVisibleSibling("next"),
|
||||
perform: () => handleMove("next"),
|
||||
}),
|
||||
],
|
||||
[findVisibleSibling, handleMove]
|
||||
);
|
||||
|
||||
const [{ isDragging }, dragRef] = useDragSidebarSection(
|
||||
section,
|
||||
titles[section]
|
||||
@@ -107,8 +212,13 @@ function DraggableSection({ section, children }: Props) {
|
||||
const showCursors = useDeferredFlag(bottomProps.isDragging);
|
||||
const isDraggingDeferred = useDeferredFlag(isDragging);
|
||||
|
||||
const contextValue = useMemo(
|
||||
() => ({ dragRef, menuActions }),
|
||||
[dragRef, menuActions]
|
||||
);
|
||||
|
||||
return (
|
||||
<SectionWrapper>
|
||||
<SectionWrapper ref={setWrapper} data-section={section}>
|
||||
{showCursors && (
|
||||
<TopDropCursor
|
||||
isActiveDrop={topProps.isOverCursor}
|
||||
@@ -117,9 +227,9 @@ function DraggableSection({ section, children }: Props) {
|
||||
/>
|
||||
)}
|
||||
<Draggable $isDragging={isDraggingDeferred}>
|
||||
<SectionDragContext.Provider value={dragRef}>
|
||||
<SidebarSectionContext.Provider value={contextValue}>
|
||||
{children}
|
||||
</SectionDragContext.Provider>
|
||||
</SidebarSectionContext.Provider>
|
||||
</Draggable>
|
||||
{showCursors && (
|
||||
<SectionDropCursor
|
||||
|
||||
@@ -13,7 +13,7 @@ import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
|
||||
type Props = {
|
||||
children: JSX.Element;
|
||||
children: React.JSX.Element;
|
||||
collectionId?: string;
|
||||
documentId?: string;
|
||||
disabled?: boolean;
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
import { CollapsedIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled, { keyframes } from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { ActionSeparator, createRootMenuAction, resolve } from "~/actions";
|
||||
import { ContextMenu } from "~/components/Menu/ContextMenu";
|
||||
import { DropdownMenu } from "~/components/Menu/DropdownMenu";
|
||||
import { OverflowMenuButton } from "~/components/Menu/OverflowMenuButton";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import useActionContext from "~/hooks/useActionContext";
|
||||
import usePersistedState from "~/hooks/usePersistedState";
|
||||
import { undraggableOnDesktop } from "~/styles";
|
||||
import { SectionDragContext } from "./DraggableSection";
|
||||
import type { Action, ActionVariant } from "~/types";
|
||||
import { SidebarSectionContext } from "./DraggableSection";
|
||||
import {
|
||||
SidebarActions,
|
||||
hoveredOrMenuOpen,
|
||||
revealActionsOnHover,
|
||||
} from "./SidebarActions";
|
||||
|
||||
type Props = {
|
||||
/** Unique header id – if passed the header will become toggleable */
|
||||
id?: string;
|
||||
title: React.ReactNode;
|
||||
/** Actions shown at the top of the header's context menu */
|
||||
actions?: ActionVariant[];
|
||||
/** Action rendered as an icon button beside the header's menu button */
|
||||
primaryAction?: Action;
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
@@ -20,9 +37,30 @@ export function getHeaderExpandedKey(id: string) {
|
||||
/**
|
||||
* Toggleable sidebar header
|
||||
*/
|
||||
export const Header: React.FC<Props> = ({ id, title, children }: Props) => {
|
||||
export const Header: React.FC<Props> = ({
|
||||
id,
|
||||
title,
|
||||
actions,
|
||||
primaryAction,
|
||||
children,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const actionContext = useActionContext({ isButton: true });
|
||||
const [firstRender, setFirstRender] = React.useState(true);
|
||||
const dragRef = React.useContext(SectionDragContext);
|
||||
const sectionContext = React.useContext(SidebarSectionContext);
|
||||
const sectionActions = sectionContext?.menuActions;
|
||||
const hasMenu = !!(actions?.length || sectionActions?.length);
|
||||
|
||||
// Dangling separators are trimmed when the menu items are rendered.
|
||||
const menuAction = React.useMemo(
|
||||
() =>
|
||||
createRootMenuAction([
|
||||
...(actions ?? []),
|
||||
ActionSeparator,
|
||||
...(sectionActions ?? []),
|
||||
]),
|
||||
[actions, sectionActions]
|
||||
);
|
||||
const [expanded, setExpanded] = usePersistedState<boolean>(
|
||||
getHeaderExpandedKey(id ?? ""),
|
||||
true
|
||||
@@ -40,12 +78,40 @@ export const Header: React.FC<Props> = ({ id, title, children }: Props) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<H3 ref={dragRef}>
|
||||
<Button onClick={handleClick} disabled={!id}>
|
||||
{title}
|
||||
{id && <Disclosure $expanded={expanded} size={20} />}
|
||||
</Button>
|
||||
</H3>
|
||||
<ContextMenu
|
||||
action={hasMenu ? menuAction : undefined}
|
||||
ariaLabel={t("Section options")}
|
||||
>
|
||||
<H3 ref={sectionContext?.dragRef}>
|
||||
<Button onClick={handleClick} disabled={!id}>
|
||||
{title}
|
||||
{id && <Disclosure $expanded={expanded} size={20} />}
|
||||
</Button>
|
||||
{hasMenu && (
|
||||
<SidebarActions>
|
||||
{primaryAction && (
|
||||
<NudeButton
|
||||
action={primaryAction}
|
||||
hideOnActionDisabled
|
||||
tooltip={{
|
||||
content: resolve<string>(primaryAction.name, actionContext),
|
||||
delay: 500,
|
||||
}}
|
||||
>
|
||||
{resolve<React.ReactNode>(primaryAction.icon, actionContext)}
|
||||
</NudeButton>
|
||||
)}
|
||||
<DropdownMenu
|
||||
action={menuAction}
|
||||
align="end"
|
||||
ariaLabel={t("Section options")}
|
||||
>
|
||||
<OverflowMenuButton />
|
||||
</DropdownMenu>
|
||||
</SidebarActions>
|
||||
)}
|
||||
</H3>
|
||||
</ContextMenu>
|
||||
{expanded && (firstRender ? children : <Fade>{children}</Fade>)}
|
||||
</>
|
||||
);
|
||||
@@ -79,7 +145,7 @@ const Button = styled.button`
|
||||
letter-spacing: 0.03em;
|
||||
margin: 0;
|
||||
padding-block: 4px;
|
||||
padding-inline: 12px 2px;
|
||||
padding-inline: 12px 32px;
|
||||
border: 0;
|
||||
background: none;
|
||||
border-radius: 4px;
|
||||
@@ -87,16 +153,9 @@ const Button = styled.button`
|
||||
transition: all 100ms ease;
|
||||
${undraggableOnDesktop()}
|
||||
|
||||
&:not(:disabled):hover,
|
||||
&:not(:disabled):active {
|
||||
background: ${s("sidebarHoverBackground")};
|
||||
&:not(:disabled) {
|
||||
cursor: var(--pointer);
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
&:not(:disabled):hover {
|
||||
color: ${s("text")};
|
||||
}
|
||||
background: var(--background);
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -114,14 +173,26 @@ const Disclosure = styled(CollapsedIcon)<{ $expanded?: boolean }>`
|
||||
`;
|
||||
|
||||
const H3 = styled.h3`
|
||||
position: relative;
|
||||
margin: 0;
|
||||
${revealActionsOnHover}
|
||||
|
||||
&:hover,
|
||||
${hoveredOrMenuOpen},
|
||||
&:focus-within {
|
||||
--background: ${s("sidebarHoverBackground")};
|
||||
|
||||
${Disclosure} {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
${hoveredOrMenuOpen} {
|
||||
${Button}:not(:disabled) {
|
||||
color: ${s("text")};
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default Header;
|
||||
@@ -168,7 +168,7 @@ const NavLink = observer(function NavLink({
|
||||
|
||||
// Whether the link was active when the click gesture began, so a fast click
|
||||
// is not also treated as a click on an already-active link.
|
||||
const wasActiveAtMouseDown = React.useRef<boolean>();
|
||||
const wasActiveAtMouseDown = React.useRef<boolean | undefined>(undefined);
|
||||
|
||||
const handleMouseDown = React.useCallback(
|
||||
(event: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
@@ -188,7 +188,16 @@ const NavLink = observer(function NavLink({
|
||||
|
||||
// Wait a frame until following the link
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(navigateTo);
|
||||
requestAnimationFrame(() => {
|
||||
navigateTo();
|
||||
|
||||
// A <Prompt> may block the navigation, in which case the location
|
||||
// is unchanged and the pending target must be released.
|
||||
const value = pendingNavigation.get();
|
||||
if (value && value.from === history.location) {
|
||||
setPendingNavigation(null);
|
||||
}
|
||||
});
|
||||
element.blur();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,21 +21,20 @@ type Props = {
|
||||
index: number;
|
||||
shareId: string;
|
||||
parentId?: string;
|
||||
ref?: React.Ref<HTMLAnchorElement>;
|
||||
};
|
||||
|
||||
function DocumentLink(
|
||||
{
|
||||
node,
|
||||
collection,
|
||||
activeDocument,
|
||||
activeDocumentId,
|
||||
prefetchDocument,
|
||||
isDraft,
|
||||
depth,
|
||||
shareId,
|
||||
}: Props,
|
||||
ref: React.RefObject<HTMLAnchorElement>
|
||||
) {
|
||||
function DocumentLink({
|
||||
node,
|
||||
collection,
|
||||
activeDocument,
|
||||
activeDocumentId,
|
||||
prefetchDocument,
|
||||
isDraft,
|
||||
depth,
|
||||
shareId,
|
||||
ref,
|
||||
}: Props) {
|
||||
const { documents } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const expansion = useSidebarExpansion();
|
||||
@@ -150,4 +149,4 @@ function DocumentLink(
|
||||
);
|
||||
}
|
||||
|
||||
export const SharedDocumentLink = observer(React.forwardRef(DocumentLink));
|
||||
export const SharedDocumentLink = observer(DocumentLink);
|
||||
@@ -0,0 +1,76 @@
|
||||
import styled, { css } from "styled-components";
|
||||
import EventBoundary from "@shared/components/EventBoundary";
|
||||
import { s } from "@shared/styles";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
|
||||
/**
|
||||
* Selector list matching a sidebar row that is hovered, pressed, or has one
|
||||
* of its menus open. Radix marks the open trigger with `data-state="open"`:
|
||||
* the row itself for a context menu, a descendant button for a dropdown.
|
||||
*/
|
||||
export const hoveredOrMenuOpen = `&:hover, &:active, &[data-state="open"], &:has([data-state="open"])`;
|
||||
|
||||
/**
|
||||
* Trailing action buttons for a sidebar row. Hidden until the row reveals
|
||||
* them, see `revealActionsOnHover`. The parent must be positioned.
|
||||
*/
|
||||
export const SidebarActions = styled(EventBoundary)<{
|
||||
$showActions?: boolean;
|
||||
}>`
|
||||
display: inline-flex;
|
||||
visibility: ${(props) => (props.$showActions ? "visible" : "hidden")};
|
||||
position: absolute;
|
||||
inset-block: 0;
|
||||
inset-inline-end: 4px;
|
||||
margin-block: auto;
|
||||
height: 24px;
|
||||
color: ${s("textTertiary")};
|
||||
background: var(--background);
|
||||
transition: opacity 50ms;
|
||||
|
||||
[data-drag-active] & {
|
||||
display: none;
|
||||
}
|
||||
|
||||
svg {
|
||||
color: ${s("textSecondary")};
|
||||
fill: currentColor;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
visibility: visible;
|
||||
|
||||
svg {
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
|
||||
${NudeButton} {
|
||||
background: transparent;
|
||||
|
||||
&:hover,
|
||||
&[aria-expanded="true"] {
|
||||
background: ${s("sidebarControlHoverBackground")};
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Mixin for a sidebar row that reveals its `SidebarActions` while hovered,
|
||||
* focused, or while one of its menus is open.
|
||||
*/
|
||||
export const revealActionsOnHover = css`
|
||||
@media (hover: hover) {
|
||||
${hoveredOrMenuOpen},
|
||||
&:focus-within {
|
||||
${SidebarActions} {
|
||||
visibility: visible;
|
||||
|
||||
svg {
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -12,54 +12,49 @@ import { HStack } from "~/components/primitives/HStack";
|
||||
|
||||
export type SidebarButtonProps = React.ComponentProps<typeof Button> & {
|
||||
position?: "top" | "bottom";
|
||||
title: React.ReactNode;
|
||||
title?: React.ReactNode;
|
||||
image: React.ReactNode;
|
||||
showMoreMenu?: boolean;
|
||||
onClick: React.MouseEventHandler<HTMLButtonElement>;
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
children?: React.ReactNode;
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
};
|
||||
|
||||
const SidebarButton = observer(
|
||||
React.forwardRef<HTMLButtonElement, SidebarButtonProps>(
|
||||
function SidebarButton_(
|
||||
{
|
||||
position = "top",
|
||||
showMoreMenu,
|
||||
image,
|
||||
title,
|
||||
children,
|
||||
onClick,
|
||||
...rest
|
||||
}: SidebarButtonProps,
|
||||
ref
|
||||
) {
|
||||
return (
|
||||
<Container
|
||||
justify="space-between"
|
||||
align="center"
|
||||
shrink={false}
|
||||
$position={position}
|
||||
>
|
||||
<Button
|
||||
{...rest}
|
||||
onClick={onClick}
|
||||
$position={position}
|
||||
as="button"
|
||||
ref={ref}
|
||||
role="button"
|
||||
>
|
||||
<Content>
|
||||
{image}
|
||||
{title && <Title>{title}</Title>}
|
||||
</Content>
|
||||
{showMoreMenu && <StyledMoreIcon />}
|
||||
</Button>
|
||||
{children}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
const SidebarButton = observer(function SidebarButton({
|
||||
position = "top",
|
||||
showMoreMenu,
|
||||
image,
|
||||
title,
|
||||
children,
|
||||
onClick,
|
||||
ref,
|
||||
...rest
|
||||
}: SidebarButtonProps) {
|
||||
return (
|
||||
<Container
|
||||
justify="space-between"
|
||||
align="center"
|
||||
shrink={false}
|
||||
$position={position}
|
||||
>
|
||||
<Button
|
||||
{...rest}
|
||||
onClick={onClick}
|
||||
$position={position}
|
||||
as="button"
|
||||
ref={ref}
|
||||
role="button"
|
||||
>
|
||||
<Content>
|
||||
{image}
|
||||
{title && <Title>{title}</Title>}
|
||||
</Content>
|
||||
{showMoreMenu && <StyledMoreIcon />}
|
||||
</Button>
|
||||
{children}
|
||||
</Container>
|
||||
);
|
||||
});
|
||||
|
||||
const StyledMoreIcon = styled(MoreIcon)`
|
||||
flex-shrink: 0;
|
||||
|
||||
@@ -2,16 +2,19 @@ import type { LocationDescriptor } from "history";
|
||||
import * as React from "react";
|
||||
import styled, { useTheme, css } from "styled-components";
|
||||
import breakpoint from "styled-components-breakpoint";
|
||||
import EventBoundary from "@shared/components/EventBoundary";
|
||||
import { ellipsis, hover, s } from "@shared/styles";
|
||||
import { isMobile } from "@shared/utils/browser";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import { UnreadBadge } from "~/components/UnreadBadge";
|
||||
import useClickIntent from "~/hooks/useClickIntent";
|
||||
import { undraggableOnDesktop } from "~/styles";
|
||||
import Disclosure from "./Disclosure";
|
||||
import type { Props as NavLinkProps } from "./NavLink";
|
||||
import NavLink from "./NavLink";
|
||||
import {
|
||||
SidebarActions,
|
||||
hoveredOrMenuOpen,
|
||||
revealActionsOnHover,
|
||||
} from "./SidebarActions";
|
||||
import type { ActionFactory, ActionWithChildren } from "~/types";
|
||||
import { ContextMenu } from "~/components/Menu/ContextMenu";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -36,6 +39,8 @@ type Props = Omit<NavLinkProps, "to"> & {
|
||||
to?: LocationDescriptor;
|
||||
/** Ref callback to access the underlying HTML element */
|
||||
innerRef?: (ref: HTMLElement | null | undefined) => void;
|
||||
/** Ref to the rendered link element */
|
||||
ref?: React.Ref<HTMLAnchorElement>;
|
||||
/** Callback fired when the link is clicked */
|
||||
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
||||
/** Callback when we expect the user to click on the link. Used for prefetching data. */
|
||||
@@ -83,32 +88,30 @@ const stopPropagation = (ev: React.MouseEvent) => {
|
||||
ev.stopPropagation();
|
||||
};
|
||||
|
||||
function SidebarLink(
|
||||
{
|
||||
icon,
|
||||
onClick,
|
||||
onClickIntent,
|
||||
to,
|
||||
label,
|
||||
active,
|
||||
isActiveDrop,
|
||||
isDraft,
|
||||
menu,
|
||||
$showActions,
|
||||
exact,
|
||||
href,
|
||||
depth,
|
||||
className,
|
||||
expanded,
|
||||
onDisclosureClick,
|
||||
disabled,
|
||||
unreadBadge,
|
||||
contextAction,
|
||||
ellipsis = true,
|
||||
...rest
|
||||
}: Props,
|
||||
ref: React.RefObject<HTMLAnchorElement>
|
||||
) {
|
||||
function SidebarLink({
|
||||
icon,
|
||||
onClick,
|
||||
onClickIntent,
|
||||
to,
|
||||
label,
|
||||
active,
|
||||
isActiveDrop,
|
||||
isDraft,
|
||||
menu,
|
||||
$showActions,
|
||||
exact,
|
||||
href,
|
||||
depth,
|
||||
className,
|
||||
expanded,
|
||||
onDisclosureClick,
|
||||
disabled,
|
||||
unreadBadge,
|
||||
contextAction,
|
||||
ellipsis = true,
|
||||
ref,
|
||||
...rest
|
||||
}: Props) {
|
||||
const hasDisclosure = expanded !== undefined;
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
@@ -177,7 +180,9 @@ function SidebarLink(
|
||||
{unreadBadge && <UnreadBadge style={unreadStyle} />}
|
||||
</Content>
|
||||
</ContextMenu>
|
||||
{menu && <Actions $showActions={$showActions}>{menu}</Actions>}
|
||||
{menu && (
|
||||
<SidebarActions $showActions={$showActions}>{menu}</SidebarActions>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -245,38 +250,6 @@ const Content = styled.span`
|
||||
min-width: 0;
|
||||
`;
|
||||
|
||||
const Actions = styled(EventBoundary)<{ $showActions?: boolean }>`
|
||||
display: inline-flex;
|
||||
visibility: ${(props) => (props.$showActions ? "visible" : "hidden")};
|
||||
|
||||
[data-drag-active] & {
|
||||
display: none;
|
||||
}
|
||||
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
inset-inline-end: 4px;
|
||||
gap: 4px;
|
||||
color: ${s("textTertiary")};
|
||||
transition: opacity 50ms;
|
||||
height: 24px;
|
||||
background: var(--background);
|
||||
|
||||
svg {
|
||||
color: ${s("textSecondary")};
|
||||
fill: currentColor;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
visibility: visible;
|
||||
|
||||
svg {
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const HiddenDisclosure = styled(Disclosure)`
|
||||
position: inherit;
|
||||
inset-inline-start: initial;
|
||||
@@ -290,13 +263,11 @@ const Link = styled(NavLink)<{
|
||||
$isDraft?: boolean;
|
||||
$disabled?: boolean;
|
||||
}>`
|
||||
&:hover,
|
||||
&:active,
|
||||
&:has([data-state="open"]) {
|
||||
${hoveredOrMenuOpen} {
|
||||
--background: ${s("sidebarHoverBackground")};
|
||||
}
|
||||
|
||||
&[aria-current="page"] ${Actions} {
|
||||
&[aria-current="page"] ${SidebarActions} {
|
||||
--background: ${s("sidebarActiveBackground")};
|
||||
}
|
||||
|
||||
@@ -364,34 +335,14 @@ const Link = styled(NavLink)<{
|
||||
font-size: 14px;
|
||||
`}
|
||||
|
||||
${revealActionsOnHover}
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover ${Actions},
|
||||
&:active ${Actions},
|
||||
&:has([data-state="open"]) ${Actions} {
|
||||
visibility: visible;
|
||||
|
||||
svg {
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:has([data-state="open"]) {
|
||||
${hoveredOrMenuOpen} {
|
||||
color: ${(props) =>
|
||||
props.$isActiveDrop ? props.theme.white : props.theme.text};
|
||||
}
|
||||
}
|
||||
|
||||
& ${Actions} {
|
||||
${NudeButton} {
|
||||
background: transparent;
|
||||
|
||||
&:hover,
|
||||
&[aria-expanded="true"] {
|
||||
background: ${s("sidebarControlHoverBackground")};
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const Label = styled.div<{ $ellipsis: boolean }>`
|
||||
@@ -409,4 +360,4 @@ const Label = styled.div<{ $ellipsis: boolean }>`
|
||||
}
|
||||
`;
|
||||
|
||||
export default React.forwardRef<HTMLAnchorElement, Props>(SidebarLink);
|
||||
export default SidebarLink;
|
||||
@@ -1,20 +1,19 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { TrashIcon } from "outline-icons";
|
||||
import { useDrop } from "react-dnd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import DocumentDelete from "~/scenes/DocumentDelete";
|
||||
import { DialogTitle } from "~/components/DialogTitle";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import * as Scenes from "~/routes/scenes";
|
||||
import { trashPath } from "~/utils/routeHelpers";
|
||||
import type { DragObject } from "../hooks/useDragAndDrop";
|
||||
import { type DragObject, useDropRef } from "../hooks/useDragAndDrop";
|
||||
import SidebarLink from "./SidebarLink";
|
||||
|
||||
function TrashLink() {
|
||||
const { policies, dialogs, documents } = useStores();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [{ isDocumentDropping }, dropToTrashRef] = useDrop({
|
||||
const [{ isDocumentDropping }, dropToTrashRef] = useDropRef({
|
||||
accept: "document",
|
||||
drop: async (item: DragObject) => {
|
||||
const document = documents.get(item.id);
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import fractionalIndex from "fractional-index";
|
||||
import * as React from "react";
|
||||
import type { ConnectDragSource } from "react-dnd";
|
||||
import type {
|
||||
ConnectDragPreview,
|
||||
ConnectDragSource,
|
||||
ConnectDropTarget,
|
||||
DragSourceHookSpec,
|
||||
DropTargetHookSpec,
|
||||
FactoryOrInstance,
|
||||
} from "react-dnd";
|
||||
import { useDrag, useDrop } from "react-dnd";
|
||||
import { getEmptyImage } from "react-dnd-html5-backend";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -31,11 +38,77 @@ export type DragObject = NavigationNode & {
|
||||
membershipId?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adapts a react-dnd connector to a ref callback. Connectors return the
|
||||
* connected node so that calls can be chained, which React does not permit
|
||||
* from a ref.
|
||||
*
|
||||
* @param connect The connector to adapt.
|
||||
* @returns a ref callback.
|
||||
*/
|
||||
function useConnectorRef(
|
||||
connect: ConnectDragSource | ConnectDropTarget
|
||||
): React.RefCallback<HTMLElement> {
|
||||
return React.useCallback(
|
||||
(node: HTMLElement | null) => void connect(node),
|
||||
[connect]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around react-dnd's `useDrag` that returns the connector as a ref
|
||||
* callback.
|
||||
*
|
||||
* @param spec The drag source specification.
|
||||
* @returns a tuple of the collected props, a ref callback and the drag preview
|
||||
* connector.
|
||||
*/
|
||||
export function useDragRef<
|
||||
DragObj = unknown,
|
||||
DropResult = unknown,
|
||||
CollectedProps = unknown,
|
||||
>(
|
||||
spec: FactoryOrInstance<
|
||||
DragSourceHookSpec<DragObj, DropResult, CollectedProps>
|
||||
>
|
||||
): [CollectedProps, React.RefCallback<HTMLElement>, ConnectDragPreview] {
|
||||
const [collected, connect, preview] = useDrag<
|
||||
DragObj,
|
||||
DropResult,
|
||||
CollectedProps
|
||||
>(spec);
|
||||
return [collected, useConnectorRef(connect), preview];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around react-dnd's `useDrop` that returns the connector as a ref
|
||||
* callback.
|
||||
*
|
||||
* @param spec The drop target specification.
|
||||
* @returns a tuple of the collected props and a ref callback.
|
||||
*/
|
||||
export function useDropRef<
|
||||
DragObj = unknown,
|
||||
DropResult = unknown,
|
||||
CollectedProps = unknown,
|
||||
>(
|
||||
spec: FactoryOrInstance<
|
||||
DropTargetHookSpec<DragObj, DropResult, CollectedProps>
|
||||
>
|
||||
): [CollectedProps, React.RefCallback<HTMLElement>] {
|
||||
const [collected, connect] = useDrop<DragObj, DropResult, CollectedProps>(
|
||||
spec
|
||||
);
|
||||
return [collected, useConnectorRef(connect)];
|
||||
}
|
||||
|
||||
function useHover(
|
||||
elementRef: React.RefObject<HTMLDivElement>,
|
||||
elementRef: React.RefObject<HTMLDivElement | null>,
|
||||
callback: () => void
|
||||
) {
|
||||
const hoverTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();
|
||||
const hoverTimeoutRef = React.useRef<
|
||||
ReturnType<typeof setTimeout> | undefined
|
||||
>(undefined);
|
||||
|
||||
const startHover = React.useCallback(() => {
|
||||
if (!hoverTimeoutRef.current) {
|
||||
@@ -71,11 +144,11 @@ function useHover(
|
||||
*/
|
||||
export function useDragStar(
|
||||
star: Star
|
||||
): [{ isDragging: boolean }, ConnectDragSource] {
|
||||
): [{ isDragging: boolean }, React.RefCallback<HTMLElement>] {
|
||||
const id = star.id;
|
||||
const { label: title, icon } = useSidebarLabelAndIcon(star);
|
||||
|
||||
const [{ isDragging }, draggableRef, preview] = useDrag({
|
||||
const [{ isDragging }, dragRef, preview] = useDragRef({
|
||||
type: "star",
|
||||
item: () => ({ id, title, icon }),
|
||||
collect: (monitor) => ({
|
||||
@@ -87,7 +160,7 @@ export function useDragStar(
|
||||
preview(getEmptyImage(), { captureDraggingState: true });
|
||||
}, [preview]);
|
||||
|
||||
return [{ isDragging }, draggableRef];
|
||||
return [{ isDragging }, dragRef];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +178,7 @@ export function useDropToCreateStar(getIndex?: () => string) {
|
||||
const { documents, stars, collections, userMemberships, groupMemberships } =
|
||||
useStores();
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOverCursor: boolean; isDragging: boolean }
|
||||
@@ -149,7 +222,7 @@ export function useDropToCreateStar(getIndex?: () => string) {
|
||||
export function useDropToReorderStar(getIndex?: () => string) {
|
||||
const { stars } = useStores();
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOverCursor: boolean; isDragging: boolean }
|
||||
@@ -178,8 +251,8 @@ export function useDropToReorderStar(getIndex?: () => string) {
|
||||
export function useDragSidebarSection(
|
||||
section: SidebarSection,
|
||||
title: string
|
||||
): [{ isDragging: boolean }, ConnectDragSource] {
|
||||
const [{ isDragging }, draggableRef, preview] = useDrag({
|
||||
): [{ isDragging: boolean }, React.RefCallback<HTMLElement>] {
|
||||
const [{ isDragging }, dragRef, preview] = useDragRef({
|
||||
type: "sidebarSection",
|
||||
item: () => ({ id: section, title }),
|
||||
collect: (monitor) => ({
|
||||
@@ -191,7 +264,7 @@ export function useDragSidebarSection(
|
||||
preview(getEmptyImage(), { captureDraggingState: true });
|
||||
}, [preview]);
|
||||
|
||||
return [{ isDragging }, draggableRef];
|
||||
return [{ isDragging }, dragRef];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +278,7 @@ export function useDropToReorderSidebarSection(
|
||||
) {
|
||||
const user = useCurrentUser();
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
{ id: SidebarSection; title: string },
|
||||
void,
|
||||
{ isOverCursor: boolean; isDragging: boolean }
|
||||
@@ -244,7 +317,7 @@ export function useDragDocument(
|
||||
const color = document?.color || node.color;
|
||||
const initial = document?.initial || node.title;
|
||||
|
||||
const [{ isDragging }, draggableRef, preview] = useDrag<
|
||||
const [{ isDragging }, dragRef, preview] = useDragRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isDragging: boolean }
|
||||
@@ -269,20 +342,20 @@ export function useDragDocument(
|
||||
preview(getEmptyImage(), { captureDraggingState: true });
|
||||
}, [preview]);
|
||||
|
||||
return [{ isDragging }, draggableRef] as const;
|
||||
return [{ isDragging }, dragRef] as const;
|
||||
}
|
||||
|
||||
export function useDropToChangeCollection(
|
||||
collection: Collection,
|
||||
expandNode: () => void,
|
||||
parentRef: React.RefObject<HTMLDivElement>
|
||||
parentRef: React.RefObject<HTMLDivElement | null>
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
const { documents, collections, dialogs, policies } = useStores();
|
||||
const can = usePolicy(collection);
|
||||
const startHover = useHover(parentRef, expandNode);
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOver: boolean; canDrop: boolean }
|
||||
@@ -360,7 +433,7 @@ export function useDropToChangeCollection(
|
||||
export function useDropToReparentDocument(
|
||||
node: NavigationNode | undefined,
|
||||
setExpanded: () => void,
|
||||
parentRef: React.RefObject<HTMLDivElement>
|
||||
parentRef: React.RefObject<HTMLDivElement | null>
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
const { documents, collections, dialogs, policies } = useStores();
|
||||
@@ -373,7 +446,7 @@ export function useDropToReparentDocument(
|
||||
|
||||
const startHover = useHover(parentRef, setExpanded);
|
||||
|
||||
return useDrop<DragObject, Promise<void>, { isOverReparent: boolean }>({
|
||||
return useDropRef<DragObject, Promise<void>, { isOverReparent: boolean }>({
|
||||
accept: ["document", "userMembership", "groupMembership"],
|
||||
drop: async (item, monitor) => {
|
||||
if (monitor.didDrop() || !node) {
|
||||
@@ -481,7 +554,7 @@ export function useDropToReorderDocument(
|
||||
|
||||
const document = documents.get(node.id);
|
||||
|
||||
return useDrop<DragObject, Promise<void>, { isOverReorder: boolean }>({
|
||||
return useDropRef<DragObject, Promise<void>, { isOverReorder: boolean }>({
|
||||
accept: "document",
|
||||
canDrop: (item: DragObject) => {
|
||||
if (
|
||||
@@ -574,7 +647,7 @@ export function useDragMembership(
|
||||
? documents.get(membership.documentId)
|
||||
: undefined;
|
||||
|
||||
const [{ isDragging }, draggableRef, preview] = useDrag({
|
||||
const [{ isDragging }, dragRef, preview] = useDragRef({
|
||||
type:
|
||||
membership instanceof UserMembership
|
||||
? "userMembership"
|
||||
@@ -604,7 +677,7 @@ export function useDragMembership(
|
||||
preview(getEmptyImage(), { captureDraggingState: true });
|
||||
}, [preview]);
|
||||
|
||||
return [{ isDragging }, draggableRef] as const;
|
||||
return [{ isDragging }, dragRef] as const;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,7 +689,7 @@ export function useDropToReorderUserMembership(getIndex?: () => string) {
|
||||
const { userMemberships } = useStores();
|
||||
const user = useCurrentUser();
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOverCursor: boolean; isDragging: boolean }
|
||||
@@ -645,7 +718,7 @@ export function useDropToArchive() {
|
||||
const { documents, collections, policies } = useStores();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOverArchiveSection: boolean; isDragging: boolean }
|
||||
@@ -682,7 +755,7 @@ export function useDropToUnpublish() {
|
||||
const { t } = useTranslation();
|
||||
const { policies, documents } = useStores();
|
||||
|
||||
return useDrop<
|
||||
return useDropRef<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOver: boolean; canDrop: boolean }
|
||||
|
||||
+18
-19
@@ -30,24 +30,23 @@ interface Props extends Omit<
|
||||
/** Callback when the switch state changes */
|
||||
onChange?: (checked: boolean) => void;
|
||||
inForm?: boolean;
|
||||
ref?: React.Ref<React.ComponentRef<typeof RadixSwitch.Root>>;
|
||||
}
|
||||
|
||||
function Switch(
|
||||
{
|
||||
width = 32,
|
||||
height = 18,
|
||||
labelPosition = "left",
|
||||
inForm = true,
|
||||
label,
|
||||
disabled,
|
||||
className,
|
||||
note,
|
||||
checked,
|
||||
onChange,
|
||||
...props
|
||||
}: Props,
|
||||
ref: React.Ref<React.ElementRef<typeof RadixSwitch.Root>>
|
||||
) {
|
||||
function Switch({
|
||||
ref,
|
||||
width = 32,
|
||||
height = 18,
|
||||
labelPosition = "left",
|
||||
inForm = true,
|
||||
label,
|
||||
disabled,
|
||||
className,
|
||||
note,
|
||||
checked,
|
||||
onChange,
|
||||
...props
|
||||
}: Props) {
|
||||
const handleCheckedChange = React.useCallback(
|
||||
(checkedState: boolean) => {
|
||||
if (onChange) {
|
||||
@@ -201,12 +200,12 @@ const StyledSwitchRoot = styled(RadixSwitch.Root)<{
|
||||
}
|
||||
|
||||
[dir="rtl"]
|
||||
&:hover:not(:disabled)[data-state="checked"]
|
||||
${StyledSwitchThumb} {
|
||||
&:hover:not(:disabled)[data-state="checked"]
|
||||
${StyledSwitchThumb} {
|
||||
transform: translateX(
|
||||
${(props) => -(props.width - props.height - HOVER_EXTRA)}px
|
||||
);
|
||||
}
|
||||
`;
|
||||
|
||||
export default React.forwardRef(Switch);
|
||||
export default Switch;
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Transition } from "framer-motion";
|
||||
import { m } from "framer-motion";
|
||||
import type { LocationDescriptor } from "history";
|
||||
import { isEqual } from "es-toolkit/compat";
|
||||
@@ -19,6 +20,8 @@ interface BaseProps {
|
||||
*/
|
||||
exactQueryString?: boolean;
|
||||
children?: React.ReactNode;
|
||||
/** Ref to the underlying button, only attached in button mode. */
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
}
|
||||
|
||||
interface LinkProps extends BaseProps {
|
||||
@@ -94,7 +97,7 @@ const Active = styled(m.div)`
|
||||
background: ${s("textSecondary")};
|
||||
`;
|
||||
|
||||
const transition = {
|
||||
const transition: Transition = {
|
||||
type: "spring",
|
||||
stiffness: 500,
|
||||
damping: 30,
|
||||
@@ -112,10 +115,7 @@ const horizontalOnly = (transform: Record<string, string>, generated: string) =>
|
||||
* matched against the current location, or as a button in controlled mode.
|
||||
* A forwarded ref is only attached in button mode.
|
||||
*/
|
||||
export const Tab = React.forwardRef<HTMLButtonElement, Props>(function Tab(
|
||||
props: Props,
|
||||
ref
|
||||
) {
|
||||
export function Tab(props: Props) {
|
||||
const { children, exact, exactQueryString } = props;
|
||||
const theme = useTheme();
|
||||
const activeStyle = {
|
||||
@@ -125,6 +125,7 @@ export const Tab = React.forwardRef<HTMLButtonElement, Props>(function Tab(
|
||||
// Button mode - controlled by onClick and active props (no `to` prop)
|
||||
if ("active" in props && !("to" in props)) {
|
||||
const {
|
||||
ref,
|
||||
active,
|
||||
exact: _exact,
|
||||
exactQueryString: _exactQueryString,
|
||||
@@ -147,7 +148,7 @@ export const Tab = React.forwardRef<HTMLButtonElement, Props>(function Tab(
|
||||
}
|
||||
|
||||
// Link mode - controlled by react-router
|
||||
const { to, ...rest } = props as LinkProps;
|
||||
const { to, ref: _ref, ...rest } = props as LinkProps;
|
||||
return (
|
||||
<TabLink
|
||||
{...rest}
|
||||
@@ -175,4 +176,4 @@ export const Tab = React.forwardRef<HTMLButtonElement, Props>(function Tab(
|
||||
)}
|
||||
</TabLink>
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import { useTooltipContext } from "./TooltipContext";
|
||||
|
||||
export type Props = {
|
||||
/** The content to display in the tooltip. */
|
||||
content?: React.ReactChild | React.ReactChild[];
|
||||
content?: React.ReactNode;
|
||||
/** A keyboard shortcut to display next to the content */
|
||||
shortcut?: React.ReactNode;
|
||||
/** Whether to show the shortcut on a new line */
|
||||
|
||||
@@ -21,11 +21,12 @@ const DrawerTrigger = DrawerPrimitive.Trigger;
|
||||
const DrawerHandle = DrawerPrimitive.Handle;
|
||||
|
||||
/** Drawer's content - renders the overlay and the actual content. */
|
||||
const DrawerContent = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
||||
>((props, ref) => {
|
||||
const { children, ...rest } = props;
|
||||
function DrawerContent(
|
||||
props: React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DrawerPrimitive.Content>>;
|
||||
}
|
||||
) {
|
||||
const { ref, children, ...rest } = props;
|
||||
const [measureRef, bounds] = useMeasure();
|
||||
|
||||
return (
|
||||
@@ -51,15 +52,16 @@ const DrawerContent = React.forwardRef<
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPrimitive.Portal>
|
||||
);
|
||||
});
|
||||
}
|
||||
DrawerContent.displayName = DrawerPrimitive.Content.displayName;
|
||||
|
||||
/** Drawer's title shown in the center. */
|
||||
const DrawerTitle = React.forwardRef<
|
||||
React.ElementRef<typeof DrawerPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
||||
>((props, ref) => {
|
||||
const { hidden, children, ...rest } = props;
|
||||
function DrawerTitle(
|
||||
props: React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DrawerPrimitive.Title>>;
|
||||
}
|
||||
) {
|
||||
const { ref, hidden, children, ...rest } = props;
|
||||
|
||||
const title = (
|
||||
<StyledText size="medium" weight="bold" as={TitleWrapper} justify="center">
|
||||
@@ -76,7 +78,7 @@ const DrawerTitle = React.forwardRef<
|
||||
)}
|
||||
</DrawerPrimitive.Title>
|
||||
);
|
||||
});
|
||||
}
|
||||
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;
|
||||
|
||||
const StyledText = styled(Text)`
|
||||
|
||||
@@ -14,7 +14,7 @@ export const Form = ({
|
||||
const tokenRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(event: React.FormEvent<HTMLFormElement>) => {
|
||||
(event: React.SubmitEvent<HTMLFormElement>) => {
|
||||
if (tokenRef.current) {
|
||||
tokenRef.current.value = getCSRFToken();
|
||||
}
|
||||
|
||||
@@ -27,14 +27,13 @@ type InputSelectTriggerProps = {
|
||||
placeholder: string;
|
||||
/** When provided, overrides the selected value rendered inside the trigger. */
|
||||
displayValue?: React.ReactNode;
|
||||
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Trigger>>;
|
||||
} & TriggerButtonProps &
|
||||
React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Trigger>;
|
||||
|
||||
const InputSelectTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof InputSelectPrimitive.Trigger>,
|
||||
InputSelectTriggerProps
|
||||
>((props, ref) => {
|
||||
const { placeholder, children, nude, displayValue, ...buttonProps } = props;
|
||||
function InputSelectTrigger(props: InputSelectTriggerProps) {
|
||||
const { ref, placeholder, children, nude, displayValue, ...buttonProps } =
|
||||
props;
|
||||
|
||||
return (
|
||||
<InputSelectPrimitive.Trigger ref={ref} asChild>
|
||||
@@ -47,20 +46,19 @@ const InputSelectTrigger = React.forwardRef<
|
||||
</SelectButton>
|
||||
</InputSelectPrimitive.Trigger>
|
||||
);
|
||||
});
|
||||
}
|
||||
InputSelectTrigger.displayName = InputSelectPrimitive.Trigger.displayName;
|
||||
|
||||
/** InputSelect's content - renders the options in a scrollable element. */
|
||||
type ContentProps = Omit<
|
||||
React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Content>,
|
||||
"position"
|
||||
>;
|
||||
> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Content>>;
|
||||
};
|
||||
|
||||
const InputSelectContent = React.forwardRef<
|
||||
React.ElementRef<typeof InputSelectPrimitive.Content>,
|
||||
ContentProps
|
||||
>((props, ref) => {
|
||||
const { children, ...rest } = props;
|
||||
function InputSelectContent(props: ContentProps) {
|
||||
const { ref, children, ...rest } = props;
|
||||
|
||||
return (
|
||||
<InputSelectPrimitive.Portal>
|
||||
@@ -71,15 +69,16 @@ const InputSelectContent = React.forwardRef<
|
||||
</StyledContent>
|
||||
</InputSelectPrimitive.Portal>
|
||||
);
|
||||
});
|
||||
}
|
||||
InputSelectContent.displayName = InputSelectPrimitive.Content.displayName;
|
||||
|
||||
/** Individual InputSelect option rendered in the menu. */
|
||||
const InputSelectItem = React.forwardRef<
|
||||
React.ElementRef<typeof InputSelectPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Item>
|
||||
>((props, ref) => {
|
||||
const { children, ...rest } = props;
|
||||
function InputSelectItem(
|
||||
props: React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Item> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Item>>;
|
||||
}
|
||||
) {
|
||||
const { ref, children, ...rest } = props;
|
||||
|
||||
return (
|
||||
<InputSelectPrimitive.Item ref={ref} {...rest} asChild>
|
||||
@@ -93,18 +92,22 @@ const InputSelectItem = React.forwardRef<
|
||||
</SelectItemWrapper>
|
||||
</InputSelectPrimitive.Item>
|
||||
);
|
||||
});
|
||||
}
|
||||
InputSelectItem.displayName = InputSelectPrimitive.Item.displayName;
|
||||
|
||||
/** Horizontal separator rendered between the options. */
|
||||
const InputSelectSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof InputSelectPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Separator>
|
||||
>((props, ref) => (
|
||||
<InputSelectPrimitive.Separator ref={ref} asChild>
|
||||
<Separator {...props} />
|
||||
</InputSelectPrimitive.Separator>
|
||||
));
|
||||
function InputSelectSeparator({
|
||||
ref,
|
||||
...props
|
||||
}: React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Separator> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Separator>>;
|
||||
}) {
|
||||
return (
|
||||
<InputSelectPrimitive.Separator ref={ref} asChild>
|
||||
<Separator {...props} />
|
||||
</InputSelectPrimitive.Separator>
|
||||
);
|
||||
}
|
||||
InputSelectSeparator.displayName = InputSelectPrimitive.Separator.displayName;
|
||||
|
||||
const Separator = styled.hr`
|
||||
@@ -112,16 +115,21 @@ const Separator = styled.hr`
|
||||
`;
|
||||
|
||||
/** Non-selectable heading rendered to group options in the menu. */
|
||||
const InputSelectHeading = React.forwardRef<
|
||||
HTMLSpanElement,
|
||||
{ children?: React.ReactNode }
|
||||
>(({ children }, ref) => (
|
||||
<InputSelectPrimitive.Group>
|
||||
<InputSelectPrimitive.Label asChild>
|
||||
<Heading ref={ref}>{children}</Heading>
|
||||
</InputSelectPrimitive.Label>
|
||||
</InputSelectPrimitive.Group>
|
||||
));
|
||||
function InputSelectHeading({
|
||||
ref,
|
||||
children,
|
||||
}: {
|
||||
children?: React.ReactNode;
|
||||
ref?: React.Ref<HTMLSpanElement>;
|
||||
}) {
|
||||
return (
|
||||
<InputSelectPrimitive.Group>
|
||||
<InputSelectPrimitive.Label asChild>
|
||||
<Heading ref={ref}>{children}</Heading>
|
||||
</InputSelectPrimitive.Label>
|
||||
</InputSelectPrimitive.Group>
|
||||
);
|
||||
}
|
||||
InputSelectHeading.displayName = "InputSelectHeading";
|
||||
|
||||
const Heading = styled(Text).attrs({
|
||||
|
||||
@@ -43,15 +43,16 @@ const SubMenu = ({ children, ...rest }: SubMenuProps) => {
|
||||
type TriggerProps = React.ComponentPropsWithoutRef<
|
||||
typeof DropdownMenuPrimitive.Trigger
|
||||
> &
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Trigger>;
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Trigger> & {
|
||||
ref?: React.Ref<
|
||||
| React.ComponentRef<typeof DropdownMenuPrimitive.Trigger>
|
||||
| React.ComponentRef<typeof ContextMenuPrimitive.Trigger>
|
||||
>;
|
||||
};
|
||||
|
||||
const MenuTrigger = React.forwardRef<
|
||||
| React.ElementRef<typeof DropdownMenuPrimitive.Trigger>
|
||||
| React.ElementRef<typeof ContextMenuPrimitive.Trigger>,
|
||||
TriggerProps
|
||||
>((props, ref) => {
|
||||
function MenuTrigger(props: TriggerProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { children, ...rest } = props;
|
||||
const { ref, children, ...rest } = props;
|
||||
|
||||
const Trigger =
|
||||
variant === "dropdown"
|
||||
@@ -59,24 +60,29 @@ const MenuTrigger = React.forwardRef<
|
||||
: ContextMenuPrimitive.Trigger;
|
||||
|
||||
return (
|
||||
<Trigger ref={ref} {...rest} asChild>
|
||||
// The trigger element type depends on the variant, so the forwarded ref is
|
||||
// a union that neither primitive accepts on its own.
|
||||
<Trigger
|
||||
ref={ref as React.Ref<HTMLButtonElement & HTMLSpanElement>}
|
||||
{...rest}
|
||||
asChild
|
||||
>
|
||||
{children}
|
||||
</Trigger>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuTrigger.displayName = "MenuTrigger";
|
||||
|
||||
type ContentProps = React.ComponentPropsWithoutRef<
|
||||
typeof DropdownMenuPrimitive.Content
|
||||
> &
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>;
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Content>>;
|
||||
};
|
||||
|
||||
const MenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
||||
ContentProps
|
||||
>((props, ref) => {
|
||||
function MenuContent(props: ContentProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { children, ...rest } = props;
|
||||
const { ref, children, ...rest } = props;
|
||||
|
||||
const Portal =
|
||||
variant === "dropdown"
|
||||
@@ -111,19 +117,20 @@ const MenuContent = React.forwardRef<
|
||||
</Content>
|
||||
</Portal>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuContent.displayName = "MenuContent";
|
||||
|
||||
type SubMenuTriggerProps = BaseItemProps &
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> &
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger>;
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {
|
||||
ref?: React.Ref<
|
||||
React.ComponentRef<typeof DropdownMenuPrimitive.SubTrigger>
|
||||
>;
|
||||
};
|
||||
|
||||
const SubMenuTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
||||
SubMenuTriggerProps
|
||||
>((props, ref) => {
|
||||
function SubMenuTrigger(props: SubMenuTriggerProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { label, icon, disabled, ...rest } = props;
|
||||
const { ref, label, icon, disabled, ...rest } = props;
|
||||
|
||||
const Trigger =
|
||||
variant === "dropdown"
|
||||
@@ -139,20 +146,21 @@ const SubMenuTrigger = React.forwardRef<
|
||||
</Components.MenuSubTrigger>
|
||||
</Trigger>
|
||||
);
|
||||
});
|
||||
}
|
||||
SubMenuTrigger.displayName = "SubMenuTrigger";
|
||||
|
||||
type SubMenuContentProps = React.ComponentPropsWithoutRef<
|
||||
typeof DropdownMenuPrimitive.SubContent
|
||||
> &
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>;
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent> & {
|
||||
ref?: React.Ref<
|
||||
React.ComponentRef<typeof DropdownMenuPrimitive.SubContent>
|
||||
>;
|
||||
};
|
||||
|
||||
const SubMenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
||||
SubMenuContentProps
|
||||
>((props, ref) => {
|
||||
function SubMenuContent(props: SubMenuContentProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { children, ...rest } = props;
|
||||
const { ref, children, ...rest } = props;
|
||||
|
||||
const Portal =
|
||||
variant === "dropdown"
|
||||
@@ -184,7 +192,7 @@ const SubMenuContent = React.forwardRef<
|
||||
</Content>
|
||||
</Portal>
|
||||
);
|
||||
});
|
||||
}
|
||||
SubMenuContent.displayName = "SubMenuContent";
|
||||
|
||||
type MenuGroupProps = {
|
||||
@@ -197,14 +205,13 @@ type MenuGroupProps = {
|
||||
Omit<
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Group>,
|
||||
"children" | "asChild"
|
||||
>;
|
||||
> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Group>>;
|
||||
};
|
||||
|
||||
const MenuGroup = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Group>,
|
||||
MenuGroupProps
|
||||
>((props, ref) => {
|
||||
function MenuGroup(props: MenuGroupProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { label, items, ...rest } = props;
|
||||
const { ref, label, items, ...rest } = props;
|
||||
|
||||
const Group =
|
||||
variant === "dropdown"
|
||||
@@ -217,7 +224,7 @@ const MenuGroup = React.forwardRef<
|
||||
{items}
|
||||
</Group>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuGroup.displayName = "MenuGroup";
|
||||
|
||||
type BaseItemProps = {
|
||||
@@ -258,7 +265,7 @@ function MenuItemShortcut({ shortcut }: { shortcut?: string[] }) {
|
||||
|
||||
type MenuButtonProps = BaseItemProps & {
|
||||
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
||||
tooltip?: React.ReactChild;
|
||||
tooltip?: React.ReactNode;
|
||||
selected?: boolean;
|
||||
dangerous?: boolean;
|
||||
} & Omit<
|
||||
@@ -268,14 +275,14 @@ type MenuButtonProps = BaseItemProps & {
|
||||
Omit<
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item>,
|
||||
"children" | "asChild" | "onClick"
|
||||
>;
|
||||
> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Item>>;
|
||||
};
|
||||
|
||||
const MenuButton = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||
MenuButtonProps
|
||||
>((props, ref) => {
|
||||
function MenuButton(props: MenuButtonProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const {
|
||||
ref,
|
||||
label,
|
||||
icon,
|
||||
tooltip,
|
||||
@@ -318,7 +325,7 @@ const MenuButton = React.forwardRef<
|
||||
) : (
|
||||
<>{button}</>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuButton.displayName = "MenuButton";
|
||||
|
||||
type MenuInternalLinkProps = BaseItemProps & {
|
||||
@@ -330,14 +337,13 @@ type MenuInternalLinkProps = BaseItemProps & {
|
||||
Omit<
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item>,
|
||||
"children" | "asChild" | "onClick"
|
||||
>;
|
||||
> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Item>>;
|
||||
};
|
||||
|
||||
const MenuInternalLink = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||
MenuInternalLinkProps
|
||||
>((props, ref) => {
|
||||
function MenuInternalLink(props: MenuInternalLinkProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { label, icon, disabled, shortcut, to, ...rest } = props;
|
||||
const { ref, label, icon, disabled, shortcut, to, ...rest } = props;
|
||||
|
||||
const Item =
|
||||
variant === "dropdown"
|
||||
@@ -353,7 +359,7 @@ const MenuInternalLink = React.forwardRef<
|
||||
</Components.MenuInternalLink>
|
||||
</Item>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuInternalLink.displayName = "MenuInternalLink";
|
||||
|
||||
type MenuExternalLinkProps = BaseItemProps & {
|
||||
@@ -366,14 +372,13 @@ type MenuExternalLinkProps = BaseItemProps & {
|
||||
Omit<
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item>,
|
||||
"children" | "asChild" | "onClick"
|
||||
>;
|
||||
> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Item>>;
|
||||
};
|
||||
|
||||
const MenuExternalLink = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||
MenuExternalLinkProps
|
||||
>((props, ref) => {
|
||||
function MenuExternalLink(props: MenuExternalLinkProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { label, icon, disabled, shortcut, href, target, ...rest } = props;
|
||||
const { ref, label, icon, disabled, shortcut, href, target, ...rest } = props;
|
||||
|
||||
const Item =
|
||||
variant === "dropdown"
|
||||
@@ -393,19 +398,19 @@ const MenuExternalLink = React.forwardRef<
|
||||
</Components.MenuExternalLink>
|
||||
</Item>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuExternalLink.displayName = "MenuExternalLink";
|
||||
|
||||
type MenuSeparatorProps = React.ComponentPropsWithoutRef<
|
||||
typeof DropdownMenuPrimitive.Separator
|
||||
> &
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>;
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Separator>>;
|
||||
};
|
||||
|
||||
const MenuSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
||||
MenuSeparatorProps
|
||||
>((props, ref) => {
|
||||
function MenuSeparator(props: MenuSeparatorProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { ref, ...rest } = props;
|
||||
|
||||
const Separator =
|
||||
variant === "dropdown"
|
||||
@@ -413,24 +418,23 @@ const MenuSeparator = React.forwardRef<
|
||||
: ContextMenuPrimitive.Separator;
|
||||
|
||||
return (
|
||||
<Separator ref={ref} {...props} asChild>
|
||||
<Separator ref={ref} {...rest} asChild>
|
||||
<Components.MenuSeparator />
|
||||
</Separator>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuSeparator.displayName = "MenuSeparator";
|
||||
|
||||
type MenuLabelProps = React.ComponentPropsWithoutRef<
|
||||
typeof DropdownMenuPrimitive.Label
|
||||
> &
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label>;
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof DropdownMenuPrimitive.Label>>;
|
||||
};
|
||||
|
||||
const MenuLabel = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
||||
MenuLabelProps
|
||||
>((props, ref) => {
|
||||
function MenuLabel(props: MenuLabelProps) {
|
||||
const { variant } = useMenuContext();
|
||||
const { children, ...rest } = props;
|
||||
const { ref, children, ...rest } = props;
|
||||
|
||||
const Label =
|
||||
variant === "dropdown"
|
||||
@@ -442,7 +446,7 @@ const MenuLabel = React.forwardRef<
|
||||
<Components.MenuHeader>{children}</Components.MenuHeader>
|
||||
</Label>
|
||||
);
|
||||
});
|
||||
}
|
||||
MenuLabel.displayName = "MenuLabel";
|
||||
|
||||
export {
|
||||
|
||||
@@ -10,17 +10,18 @@ const Popover = PopoverPrimitive.Root;
|
||||
|
||||
const PopoverAnchor = PopoverPrimitive.Anchor;
|
||||
|
||||
const PopoverTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof PopoverPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Trigger>
|
||||
>((props, ref) => {
|
||||
const { children, ...rest } = props;
|
||||
function PopoverTrigger(
|
||||
props: React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Trigger> & {
|
||||
ref?: React.Ref<React.ComponentRef<typeof PopoverPrimitive.Trigger>>;
|
||||
}
|
||||
) {
|
||||
const { ref, children, ...rest } = props;
|
||||
return (
|
||||
<PopoverPrimitive.Trigger ref={ref} {...rest} asChild>
|
||||
{children}
|
||||
</PopoverPrimitive.Trigger>
|
||||
);
|
||||
});
|
||||
}
|
||||
PopoverTrigger.displayName = PopoverPrimitive.Trigger.displayName;
|
||||
|
||||
type ContentProps = {
|
||||
@@ -34,16 +35,17 @@ type ContentProps = {
|
||||
scrollable?: boolean;
|
||||
/** Shrink the padding of the popover */
|
||||
shrink?: boolean;
|
||||
ref?: React.Ref<React.ComponentRef<typeof PopoverPrimitive.Content>>;
|
||||
} & React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>;
|
||||
|
||||
const PopoverContent = React.forwardRef<
|
||||
React.ElementRef<typeof PopoverPrimitive.Content>,
|
||||
ContentProps
|
||||
>((props, forwardedRef) => {
|
||||
const ref = React.useRef<React.ElementRef<typeof PopoverPrimitive.Content>>();
|
||||
const timeoutRef = React.useRef<NodeJS.Timeout>();
|
||||
function PopoverContent(props: ContentProps) {
|
||||
const ref = React.useRef<
|
||||
React.ComponentRef<typeof PopoverPrimitive.Content> | undefined
|
||||
>(undefined);
|
||||
const timeoutRef = React.useRef<NodeJS.Timeout | undefined>(undefined);
|
||||
const container = usePortalContext();
|
||||
const {
|
||||
ref: forwardedRef,
|
||||
width,
|
||||
minWidth,
|
||||
minHeight,
|
||||
@@ -92,7 +94,7 @@ const PopoverContent = React.forwardRef<
|
||||
</StyledContent>
|
||||
</PopoverPrimitive.Portal>
|
||||
);
|
||||
});
|
||||
}
|
||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
||||
|
||||
type StyledContentProps = {
|
||||
|
||||
Loaded 100 of 342 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user