mirror of
https://github.com/outline/outline.git
synced 2026-12-05 18:55:10 +03:00
Merge branch 'main' of github.com:outline/outline into tommoor/collection-multiplayer-editing
# Conflicts: # app/scenes/Document/components/MultiplayerEditor.tsx # server/collaboration/PersistenceExtension.ts # server/commands/documentCollaborativeUpdater.ts # server/models/Collection.ts # server/models/Document.ts # server/queues/processors/RevisionsProcessor.ts # server/routes/api/collections/collections.ts
This commit is contained in:
629 files changed
+18207
-6529
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
-25
@@ -4,7 +4,6 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
NODE_ENV: test
|
||||
@@ -19,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 }}
|
||||
@@ -61,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
|
||||
@@ -80,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
|
||||
@@ -89,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
|
||||
@@ -98,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]
|
||||
@@ -110,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
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Local oxlint plugin with MobX-specific rules.
|
||||
*/
|
||||
|
||||
/** Returns true if the decorator is `@observable` or `@observable.<modifier>`. */
|
||||
function isObservableDecorator(decorator) {
|
||||
const expression = decorator.expression;
|
||||
|
||||
if (expression.type === "Identifier") {
|
||||
return expression.name === "observable";
|
||||
}
|
||||
|
||||
if (expression.type === "MemberExpression") {
|
||||
return (
|
||||
expression.object.type === "Identifier" &&
|
||||
expression.object.name === "observable"
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns true if the expression is a `makeObservable(this, …)` call. */
|
||||
function isMakeObservableCall(expression) {
|
||||
return (
|
||||
expression.type === "CallExpression" &&
|
||||
expression.callee.type === "Identifier" &&
|
||||
expression.callee.name === "makeObservable" &&
|
||||
expression.arguments.length > 0 &&
|
||||
expression.arguments[0].type === "ThisExpression"
|
||||
);
|
||||
}
|
||||
|
||||
/** Returns the property name if the expression is `this.<name> = …`, else null. */
|
||||
function assignedThisProperty(expression) {
|
||||
if (
|
||||
expression.type !== "AssignmentExpression" ||
|
||||
expression.left.type !== "MemberExpression" ||
|
||||
expression.left.object.type !== "ThisExpression" ||
|
||||
expression.left.property.type !== "Identifier"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return expression.left.property.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks the constructor body and returns the set of `this.<name>` properties
|
||||
* assigned before `makeObservable(this)` is called, or null if the constructor
|
||||
* never calls it.
|
||||
*/
|
||||
function propertiesAssignedBeforeMakeObservable(classBody) {
|
||||
const ctor = classBody.body.find(
|
||||
(member) =>
|
||||
member.type === "MethodDefinition" && member.kind === "constructor"
|
||||
);
|
||||
if (!ctor?.value?.body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const assigned = new Set();
|
||||
for (const statement of ctor.value.body.body) {
|
||||
if (statement.type !== "ExpressionStatement") {
|
||||
continue;
|
||||
}
|
||||
if (isMakeObservableCall(statement.expression)) {
|
||||
return assigned;
|
||||
}
|
||||
const name = assignedThisProperty(statement.expression);
|
||||
if (name) {
|
||||
assigned.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
const plugin = {
|
||||
meta: {
|
||||
name: "mobx",
|
||||
},
|
||||
rules: {
|
||||
"observable-needs-initializer": {
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: {
|
||||
description:
|
||||
"Require an initializer on @observable class fields in classes that call makeObservable(this). A field that does not exist as an own property when makeObservable runs is silently skipped by MobX.",
|
||||
},
|
||||
messages: {
|
||||
missing:
|
||||
"@observable field '{{name}}' has no initializer, so makeObservable() will silently skip it. Add `= undefined` or another initial value.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
return {
|
||||
ClassBody(node) {
|
||||
const assigned = propertiesAssignedBeforeMakeObservable(node);
|
||||
if (assigned === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const member of node.body) {
|
||||
if (
|
||||
member.type !== "PropertyDefinition" ||
|
||||
member.value !== null ||
|
||||
member.static ||
|
||||
member.declare ||
|
||||
member.key.type !== "Identifier" ||
|
||||
assigned.has(member.key.name)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const decorators = member.decorators ?? [];
|
||||
if (!decorators.some(isObservableDecorator)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node: member,
|
||||
messageId: "missing",
|
||||
data: { name: member.key.name },
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default plugin;
|
||||
+8
-26
@@ -9,7 +9,9 @@
|
||||
"patches/**",
|
||||
"*.d.ts"
|
||||
],
|
||||
"jsPlugins": ["./.oxlint/mobx.mjs"],
|
||||
"rules": {
|
||||
"mobx/observable-needs-initializer": "error",
|
||||
"for-direction": "error",
|
||||
"no-async-promise-executor": "error",
|
||||
"no-case-declarations": "error",
|
||||
@@ -68,6 +70,12 @@
|
||||
"valid-typeof": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["**/*.{ts,tsx}"],
|
||||
"rules": {
|
||||
"no-redeclare": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["**/*.{js,jsx,ts,tsx}"],
|
||||
"rules": {
|
||||
@@ -125,32 +133,6 @@
|
||||
"react-hooks/exhaustive-deps": "error"
|
||||
},
|
||||
"plugins": ["eslint", "oxc", "react", "typescript", "import"]
|
||||
},
|
||||
{
|
||||
"files": ["shared/**/*.{js,jsx,ts,tsx}"],
|
||||
"rules": {
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"paths": [
|
||||
{
|
||||
"name": "prosemirror-tables",
|
||||
"importNames": [
|
||||
"addRowBefore",
|
||||
"addRowAfter",
|
||||
"addColumnBefore",
|
||||
"addColumnAfter"
|
||||
],
|
||||
"message": "Use the wrappers from shared/editor/commands/table instead, which respect the target index and place the cursor in the inserted cell."
|
||||
},
|
||||
{
|
||||
"name": "sonner",
|
||||
"message": "Do not import a toast library within shared; surface notifications through the onNotice callback so shared code stays decoupled from the app's toast implementation."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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.9.1
|
||||
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-07-13
|
||||
Change Date: 2030-09-09
|
||||
|
||||
Change License: Apache License, Version 2.0
|
||||
|
||||
|
||||
@@ -16,6 +16,18 @@
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
"paths": [
|
||||
{
|
||||
"name": "prosemirror-tables",
|
||||
"importNames": [
|
||||
"addRowBefore",
|
||||
"addRowAfter",
|
||||
"addColumnBefore",
|
||||
"addColumnAfter"
|
||||
],
|
||||
"message": "Use the wrappers from shared/editor/commands/table instead, which respect the target index and place the cursor in the inserted cell."
|
||||
}
|
||||
],
|
||||
"patterns": [
|
||||
{
|
||||
"group": ["mime-types"],
|
||||
|
||||
@@ -62,6 +62,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";
|
||||
@@ -719,10 +720,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,
|
||||
@@ -744,6 +755,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,
|
||||
@@ -766,6 +778,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,
|
||||
@@ -787,6 +800,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,
|
||||
@@ -1150,6 +1164,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),
|
||||
@@ -1364,7 +1379,8 @@ export const searchDocumentsForQueryActionFactory = (query: string) =>
|
||||
priority: -1,
|
||||
icon: <SearchIcon />,
|
||||
to: searchPath({ query }),
|
||||
visible: ({ location }) => location.pathname !== searchPath(),
|
||||
visible: ({ location, isMCP }) =>
|
||||
!isMCP && location.pathname !== searchPath(),
|
||||
});
|
||||
|
||||
export const moveDocumentToCollection = createAction({
|
||||
@@ -1449,10 +1465,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(
|
||||
@@ -1462,16 +1479,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>
|
||||
/>
|
||||
),
|
||||
});
|
||||
},
|
||||
|
||||
@@ -55,6 +55,7 @@ export const navigateToRecentSearchQueryActionFactory = (
|
||||
name: searchQuery.query,
|
||||
analyticsName: "Navigate to recent search query",
|
||||
icon: <SearchIcon />,
|
||||
visible: ({ isMCP }) => !isMCP,
|
||||
to: searchPath({ query: searchQuery.query }),
|
||||
});
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ export const deleteRevision = createAction({
|
||||
dangerous: true,
|
||||
visible: ({ activeDocumentId }) =>
|
||||
!!activeDocumentId && stores.policies.abilities(activeDocumentId).update,
|
||||
perform: async ({ t, event, location, activeDocumentId }) => {
|
||||
perform: async ({ t, event, location, activeDocumentId, sidebarContext }) => {
|
||||
event?.preventDefault();
|
||||
if (!activeDocumentId) {
|
||||
return;
|
||||
@@ -113,7 +113,7 @@ export const deleteRevision = createAction({
|
||||
const revision = stores.revisions.get(revisionId);
|
||||
await revision?.delete();
|
||||
toast.success(t("This version of the document was deleted"));
|
||||
history.push(documentHistoryPath(document));
|
||||
history.push(documentHistoryPath(document), { sidebarContext });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { createAction } from "~/actions";
|
||||
import { DocumentsSection, NavigationSection } from "~/actions/sections";
|
||||
|
||||
/**
|
||||
* Actions that are only registered as WebMCP tools, never in menus or the
|
||||
* command bar. Names and descriptions are intentionally not translated as
|
||||
* they are read by agents, not users.
|
||||
*/
|
||||
export const getCurrentContext = createAction({
|
||||
name: "Get current context",
|
||||
analyticsName: "Get current context",
|
||||
section: NavigationSection,
|
||||
description:
|
||||
"Returns the user's current location in the app as JSON, including the active document and collection if any.",
|
||||
mcp: {},
|
||||
perform: ({ stores, location }) => {
|
||||
const document = stores.documents.active;
|
||||
const collection = stores.collections.active;
|
||||
|
||||
return JSON.stringify({
|
||||
path: location.pathname,
|
||||
user: stores.auth.user
|
||||
? { id: stores.auth.user.id, name: stores.auth.user.name }
|
||||
: undefined,
|
||||
document: document
|
||||
? {
|
||||
id: document.id,
|
||||
title: document.titleWithDefault,
|
||||
path: document.url,
|
||||
}
|
||||
: undefined,
|
||||
collection: collection
|
||||
? { id: collection.id, name: collection.name, path: collection.path }
|
||||
: undefined,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const searchWorkspace = createAction({
|
||||
name: "Search workspace",
|
||||
analyticsName: "Search workspace",
|
||||
section: DocumentsSection,
|
||||
description:
|
||||
"Searches all documents the user can access and returns the top matches as JSON, each with an id, title, path, and a snippet of matching context.",
|
||||
mcp: {
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
query: {
|
||||
type: "string",
|
||||
description: "The text to search for.",
|
||||
},
|
||||
},
|
||||
required: ["query"],
|
||||
},
|
||||
},
|
||||
perform: async ({ stores, mcpArgs }) => {
|
||||
const query = typeof mcpArgs?.query === "string" ? mcpArgs.query : "";
|
||||
if (!query) {
|
||||
return "A query argument is required.";
|
||||
}
|
||||
|
||||
const results = await stores.documents.search({ query, limit: 10 });
|
||||
|
||||
return JSON.stringify(
|
||||
results.map((result) => ({
|
||||
id: result.document.id,
|
||||
title: result.document.titleWithDefault,
|
||||
path: result.document.url,
|
||||
context: result.context,
|
||||
}))
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const rootWebMCPActions = [getCurrentContext, searchWorkspace];
|
||||
+20
-17
@@ -46,22 +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"
|
||||
: "contextmenu",
|
||||
});
|
||||
}
|
||||
return definition.perform(context);
|
||||
}
|
||||
: () => {},
|
||||
perform: definition.perform ?? (() => {}),
|
||||
id: definition.id ?? uuidv4(),
|
||||
};
|
||||
}
|
||||
@@ -180,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,
|
||||
@@ -351,10 +336,28 @@ 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) {
|
||||
return result.catch((err: Error) => {
|
||||
// WebMCP callers surface errors to the agent instead of a toast.
|
||||
if (context.isMCP) {
|
||||
throw err;
|
||||
}
|
||||
toast.error(err.message);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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={label}
|
||||
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);
|
||||
@@ -11,7 +11,7 @@ type Props = {
|
||||
};
|
||||
|
||||
// TODO: Refactor this component to allow injection from plugins
|
||||
const Analytics: React.FC = ({ children }: Props) => {
|
||||
const Analytics: React.FC<Props> = ({ children }: Props) => {
|
||||
// Google Analytics 3
|
||||
React.useEffect(() => {
|
||||
if (!env.GOOGLE_ANALYTICS_ID?.startsWith("UA-")) {
|
||||
|
||||
@@ -2,16 +2,20 @@ import { RovingTabIndexProvider } from "@getoutline/react-roving-tabindex";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
|
||||
type Props = React.HTMLAttributes<HTMLDivElement> & {
|
||||
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) => {
|
||||
|
||||
@@ -8,8 +8,10 @@ import Layout from "~/components/Layout";
|
||||
import RegisterKeyDown from "~/components/RegisterKeyDown";
|
||||
import { RightSidebarProvider } from "~/components/RightSidebarContext";
|
||||
import Sidebar from "~/components/Sidebar";
|
||||
import { rootWebMCPActions } from "~/actions/definitions/webmcp";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import useWebMCPActions from "~/hooks/useWebMCPActions";
|
||||
import { usePostLoginPath } from "~/hooks/useLastVisitedPath";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -36,7 +38,7 @@ type Props = {
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
const AuthenticatedLayout: React.FC = ({ children }: Props) => {
|
||||
const AuthenticatedLayout: React.FC<Props> = ({ children }: Props) => {
|
||||
const { ui, auth } = useStores();
|
||||
const location = useLocation();
|
||||
const layoutRef = React.useRef<HTMLDivElement>(null);
|
||||
@@ -45,6 +47,7 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => {
|
||||
const [spendPostLoginPath] = usePostLoginPath();
|
||||
|
||||
useKeyDown(".", () => ui.toggleCollapsedSidebar(), { metaKey: true });
|
||||
useWebMCPActions(rootWebMCPActions);
|
||||
|
||||
const goToSearch = (ev: KeyboardEvent) => {
|
||||
if (!ev.metaKey && !ev.ctrlKey) {
|
||||
|
||||
@@ -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,
|
||||
@@ -194,16 +195,16 @@ const Button = <T extends React.ElementType = "button">(
|
||||
{...rest}
|
||||
>
|
||||
<Inner hasIcon={hasIcon} hasText={hasText} disclosure={disclosure}>
|
||||
{hasIcon && ic}
|
||||
{hasIcon && typeof ic !== "function" && ic}
|
||||
{hasText && <Label hasIcon={hasIcon}>{children || value}</Label>}
|
||||
{disclosure && <StyledDisclosureIcon />}
|
||||
</Inner>
|
||||
</RealButton>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const StyledDisclosureIcon = styled(DisclosureIcon)`
|
||||
opacity: 0.8;
|
||||
`;
|
||||
|
||||
export default React.forwardRef(Button);
|
||||
export default Button;
|
||||
@@ -3,6 +3,8 @@ import { observer } from "mobx-react";
|
||||
import { useState, useMemo, useEffect, useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type Document from "~/models/Document";
|
||||
import type User from "~/models/User";
|
||||
import type { AvatarProps } from "~/components/Avatar";
|
||||
import { AvatarSize, AvatarWithPresence } from "~/components/Avatar";
|
||||
import DocumentViews from "~/components/DocumentViews";
|
||||
import Facepile from "~/components/Facepile";
|
||||
@@ -118,7 +120,7 @@ function Collaborators(props: Props) {
|
||||
);
|
||||
|
||||
const renderAvatar = useCallback(
|
||||
({ model: collaborator, ...rest }) => {
|
||||
({ model: collaborator, ...rest }: AvatarProps & { model: User }) => {
|
||||
const isPresent = presentIds.has(collaborator.id);
|
||||
const isEditing = editingIds.has(collaborator.id);
|
||||
const isObserving = observingUserId === collaborator.id;
|
||||
|
||||
@@ -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")})`;
|
||||
|
||||
@@ -52,7 +52,7 @@ type Props = {
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
const KBarPortal: React.FC = ({ children }: Props) => {
|
||||
const KBarPortal: React.FC<Props> = ({ children }: Props) => {
|
||||
const { showing } = useKBar((state) => ({
|
||||
showing: state.visualState !== "hidden",
|
||||
}));
|
||||
|
||||
@@ -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;
|
||||
@@ -34,7 +34,7 @@ type Props = {
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
const KBarPortal: React.FC = ({ children }: Props) => {
|
||||
const KBarPortal: React.FC<Props> = ({ children }: Props) => {
|
||||
const { showing } = useKBar((state) => ({
|
||||
showing: state.visualState !== "hidden",
|
||||
}));
|
||||
|
||||
@@ -46,6 +46,7 @@ const useRecentDocumentActions = (count = recentDocumentCount) => {
|
||||
name: item.titleWithDefault,
|
||||
analyticsName: "Recently viewed document",
|
||||
section: RecentSection,
|
||||
visible: ({ isMCP }) => !isMCP,
|
||||
description: documentBreadcrumbText(item, t),
|
||||
icon: item.icon ? (
|
||||
<Icon
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
|
||||
const plainTextCache = new LRUCache<{ updatedAt: string; text: string }>({
|
||||
max: 100,
|
||||
storage: "memory",
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -89,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();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,10 @@ const useTemplatesAction = () => {
|
||||
<NewDocumentIcon />
|
||||
),
|
||||
keywords: "create",
|
||||
visible: ({ currentTeamId, activeCollectionId, stores }) => {
|
||||
visible: ({ currentTeamId, activeCollectionId, stores, isMCP }) => {
|
||||
if (isMCP) {
|
||||
return false;
|
||||
}
|
||||
if (activeCollectionId) {
|
||||
return (
|
||||
stores.policies.abilities(activeCollectionId).createDocument &&
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -83,12 +83,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();
|
||||
@@ -334,4 +338,4 @@ const SmallSlash = styled(GoToIcon)`
|
||||
opacity: 0.5;
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(DocumentBreadcrumb));
|
||||
export default observer(DocumentBreadcrumb);
|
||||
@@ -1,4 +1,4 @@
|
||||
import { action, computed, observable } from "mobx";
|
||||
import { action, computed, makeObservable, observable } from "mobx";
|
||||
import type { PropsWithChildren } from "react";
|
||||
import { createContext, useContext, useMemo } from "react";
|
||||
import type { Node } from "prosemirror-model";
|
||||
@@ -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,26 @@ 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);
|
||||
}
|
||||
|
||||
@computed
|
||||
get hasHeadings() {
|
||||
// Headings inside tables are not listed in the table of contents.
|
||||
@@ -63,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;
|
||||
@@ -77,7 +123,7 @@ class DocumentContext {
|
||||
|
||||
/** The ProseMirror document currently held by the editor */
|
||||
@observable.ref
|
||||
private editorDoc: Node | undefined;
|
||||
private editorDoc: Node | undefined = undefined;
|
||||
|
||||
private updateHeadings() {
|
||||
const currHeadings = this.editor?.getHeadings() ?? [];
|
||||
|
||||
@@ -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 =
|
||||
@@ -135,7 +130,6 @@ function DocumentListItem(
|
||||
document.asNavigationNode,
|
||||
0,
|
||||
document,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
@@ -446,4 +440,4 @@ const ResultContext = styled(Highlight)`
|
||||
overflow: hidden;
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(DocumentListItem));
|
||||
export default observer(DocumentListItem);
|
||||
@@ -5,13 +5,13 @@ import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { s, ellipsis } from "@shared/styles";
|
||||
import { ellipsis } from "@shared/styles";
|
||||
import type Document from "~/models/Document";
|
||||
import type Revision from "~/models/Revision";
|
||||
import DocumentBreadcrumb from "~/components/DocumentBreadcrumb";
|
||||
import DocumentTasks from "~/components/DocumentTasks";
|
||||
import Flex from "~/components/Flex";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import { MetaButton, Separator, metaStyles } from "~/components/HeaderMeta";
|
||||
import Time from "~/components/Time";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -86,7 +86,9 @@ const DocumentMeta: React.FC<Props> = ({
|
||||
<span>
|
||||
{revision.createdBy?.id === user.id
|
||||
? t("You updated")
|
||||
: t("{{ userName }} updated", { userName })}{" "}
|
||||
: t("{{ userName }} updated", {
|
||||
userName: revision.createdBy?.name ?? t("Unknown"),
|
||||
})}{" "}
|
||||
<Time dateTime={revision.createdAt} addSuffix />
|
||||
</span>
|
||||
);
|
||||
@@ -229,42 +231,12 @@ const DocumentMeta: React.FC<Props> = ({
|
||||
);
|
||||
};
|
||||
|
||||
/** A button that visually matches the surrounding meta text. */
|
||||
export const MetaButton = styled(NudeButton)`
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: 0;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: inherit;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
export const Separator = styled.span`
|
||||
padding: 0 0.4em;
|
||||
|
||||
&::after {
|
||||
content: "•";
|
||||
}
|
||||
`;
|
||||
|
||||
const Strong = styled.strong`
|
||||
font-weight: 550;
|
||||
`;
|
||||
|
||||
const Container = styled(Flex)<{ $rtl?: boolean }>`
|
||||
justify-content: ${(props) => (props.$rtl ? "flex-end" : "flex-start")};
|
||||
color: ${s("textTertiary")};
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
${metaStyles}
|
||||
`;
|
||||
|
||||
const Viewed = styled.span`
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { errToString } from "@shared/utils/error";
|
||||
import { s, ellipsis } from "@shared/styles";
|
||||
import EventBoundary from "@shared/components/EventBoundary";
|
||||
|
||||
type Props = Omit<React.HTMLAttributes<HTMLInputElement>, "onSubmit"> & {
|
||||
type Props = Omit<React.InputHTMLAttributes<HTMLInputElement>, "onSubmit"> & {
|
||||
/** A callback when the title is submitted. */
|
||||
onSubmit: (title: string) => Promise<void> | void;
|
||||
/** A callback when the editing status changes. */
|
||||
@@ -20,6 +20,7 @@ type Props = Omit<React.HTMLAttributes<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;
|
||||
+29
-80
@@ -1,22 +1,17 @@
|
||||
import { difference } from "es-toolkit/compat";
|
||||
import { observer } from "mobx-react";
|
||||
import { DOMParser as ProsemirrorDOMParser } from "prosemirror-model";
|
||||
import { TextSelection } from "prosemirror-state";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import { mergeRefs } from "react-merge-refs";
|
||||
import type { Optional } from "utility-types";
|
||||
import insertFiles from "@shared/editor/commands/insertFiles";
|
||||
import EditorContainer from "@shared/editor/components/Styles";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||
import { getDataTransferFiles } from "@shared/utils/files";
|
||||
import { AttachmentValidation } from "@shared/validations";
|
||||
import ClickablePadding from "~/components/ClickablePadding";
|
||||
import ErrorBoundary from "~/components/ErrorBoundary";
|
||||
import PlaceholderDocument from "~/components/PlaceholderDocument";
|
||||
import type { Props as EditorProps, Editor as SharedEditor } from "~/editor";
|
||||
import { toastNotice } from "~/editor/toastNotice";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useEditorClickHandlers from "~/hooks/useEditorClickHandlers";
|
||||
import useEmbeds from "~/hooks/useEmbeds";
|
||||
@@ -37,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,
|
||||
@@ -50,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>(), []);
|
||||
@@ -135,61 +130,9 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
}, [localRef]);
|
||||
|
||||
const handleDrop = React.useCallback(
|
||||
(event: React.DragEvent<HTMLDivElement>) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const files = getDataTransferFiles(event);
|
||||
|
||||
const view = localRef?.current?.view;
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find a valid position at the end of the document to insert our content
|
||||
const pos = TextSelection.near(
|
||||
view.state.doc.resolve(view.state.doc.nodeSize - 2)
|
||||
).from;
|
||||
|
||||
// If there are no files in the drop event attempt to parse the html
|
||||
// as a fragment and insert it at the end of the document
|
||||
if (files.length === 0) {
|
||||
const text =
|
||||
event.dataTransfer.getData("text/html") ||
|
||||
event.dataTransfer.getData("text/plain");
|
||||
|
||||
const dom = new DOMParser().parseFromString(text, "text/html");
|
||||
|
||||
view.dispatch(
|
||||
view.state.tr.insert(
|
||||
pos,
|
||||
ProsemirrorDOMParser.fromSchema(view.state.schema).parse(dom)
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert all files as attachments if any of the files are not images.
|
||||
const isAttachment = files.some(
|
||||
(file) => !AttachmentValidation.imageContentTypes.includes(file.type)
|
||||
);
|
||||
|
||||
return insertFiles(view, event, pos, files, {
|
||||
uploadFile: handleUploadFile,
|
||||
onFileUploadStart: handleFileUploadStart,
|
||||
onFileUploadStop: handleFileUploadStop,
|
||||
onFileUploadProgress: handleFileUploadProgress,
|
||||
onNotice: toastNotice,
|
||||
isAttachment,
|
||||
});
|
||||
},
|
||||
[
|
||||
localRef,
|
||||
handleFileUploadStart,
|
||||
handleFileUploadStop,
|
||||
handleFileUploadProgress,
|
||||
handleUploadFile,
|
||||
]
|
||||
(event: React.DragEvent<HTMLDivElement>) =>
|
||||
localRef.current?.insertDroppedContent(event),
|
||||
[]
|
||||
);
|
||||
|
||||
// see: https://stackoverflow.com/a/50233827/192065
|
||||
@@ -287,21 +230,27 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
</div>
|
||||
</EditorContainer>
|
||||
) : (
|
||||
<LazyLoadedEditor
|
||||
key={props.extensions?.length || 0}
|
||||
ref={mergeRefs([ref, localRef, handleRefChanged])}
|
||||
uploadFile={handleUploadFile}
|
||||
embeds={embeds}
|
||||
userPreferences={preferences}
|
||||
{...props}
|
||||
onClickLink={handleClickLink}
|
||||
onChange={handleChange}
|
||||
onFileUploadStart={handleFileUploadStart}
|
||||
onFileUploadStop={handleFileUploadStop}
|
||||
onFileUploadProgress={handleFileUploadProgress}
|
||||
placeholder={props.placeholder || ""}
|
||||
defaultValue={props.defaultValue || ""}
|
||||
/>
|
||||
// The boundary must live between the lazy editor and any ancestor
|
||||
// with effects or refs. If the suspension reached an outer boundary
|
||||
// React 18 would hide mounted ancestors and destroy their effects,
|
||||
// re-running provider setup and ref callbacks in a loop.
|
||||
<React.Suspense fallback={<PlaceholderDocument delay={500} />}>
|
||||
<LazyLoadedEditor
|
||||
key={props.extensions?.length || 0}
|
||||
ref={mergeRefs([ref, localRef, handleRefChanged])}
|
||||
uploadFile={handleUploadFile}
|
||||
embeds={embeds}
|
||||
userPreferences={preferences}
|
||||
{...props}
|
||||
onClickLink={handleClickLink}
|
||||
onChange={handleChange}
|
||||
onFileUploadStart={handleFileUploadStart}
|
||||
onFileUploadStop={handleFileUploadStop}
|
||||
onFileUploadProgress={handleFileUploadProgress}
|
||||
placeholder={props.placeholder || ""}
|
||||
defaultValue={props.defaultValue || ""}
|
||||
/>
|
||||
</React.Suspense>
|
||||
)}
|
||||
{props.editorStyle?.paddingBottom && !props.readOnly && (
|
||||
<ClickablePadding
|
||||
@@ -316,4 +265,4 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
);
|
||||
}
|
||||
|
||||
export default observer(React.forwardRef(Editor));
|
||||
export default observer(Editor);
|
||||
@@ -29,6 +29,14 @@ const topHandlerNames = [
|
||||
const isWithinEditor = (target: EventTarget | null): boolean =>
|
||||
target instanceof Element && Boolean(target.closest(".ProseMirror"));
|
||||
|
||||
// A file dragged over an element marked `data-drop-area`, which accepts native
|
||||
// file drops itself. react-dnd never tracks these drags, so its handlers would
|
||||
// otherwise reject them.
|
||||
const isFileOverDropArea = (event: DragEvent): boolean =>
|
||||
Boolean(event.dataTransfer?.types.includes("Files")) &&
|
||||
event.target instanceof Element &&
|
||||
Boolean(event.target.closest("[data-drop-area]"));
|
||||
|
||||
/**
|
||||
* An HTML5 drag-and-drop backend that ignores drag events originating within the
|
||||
* rich text editor so that ProseMirror can handle them itself.
|
||||
@@ -57,7 +65,7 @@ export const EditorAwareHTML5Backend: BackendFactory = (
|
||||
const original = handlers[name];
|
||||
if (typeof original === "function") {
|
||||
handlers[name] = (event: DragEvent) => {
|
||||
if (isWithinEditor(event.target)) {
|
||||
if (isWithinEditor(event.target) || isFileOverDropArea(event)) {
|
||||
return;
|
||||
}
|
||||
// A drag that began or entered the page over the editor is never
|
||||
|
||||
@@ -8,7 +8,7 @@ import Input, { LabelText } from "~/components/Input";
|
||||
import Text from "~/components/Text";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { uploadFile } from "~/utils/files";
|
||||
import { compressImage } from "~/utils/compressImage";
|
||||
import { ImageHelper } from "~/utils/ImageHelper";
|
||||
import { generateEmojiNameFromFilename } from "~/utils/emoji";
|
||||
import { useEmojiFileUpload, EmojiImageDropZone } from "./Components";
|
||||
|
||||
@@ -55,7 +55,7 @@ export function EmojiCreateDialog({ onSubmit }: Props) {
|
||||
const fileToUpload =
|
||||
file.type === "image/gif"
|
||||
? file
|
||||
: await compressImage(file, {
|
||||
: await ImageHelper.compress(file, {
|
||||
maxHeight: 64,
|
||||
maxWidth: 64,
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import Text from "~/components/Text";
|
||||
import type Emoji from "~/models/Emoji";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { uploadFile } from "~/utils/files";
|
||||
import { compressImage } from "~/utils/compressImage";
|
||||
import { ImageHelper } from "~/utils/ImageHelper";
|
||||
import { useEmojiFileUpload, EmojiImageDropZone } from "./Components";
|
||||
|
||||
interface Props {
|
||||
@@ -38,7 +38,7 @@ export function EmojiReplaceDialog({ emoji, onSubmit }: Props) {
|
||||
const fileToUpload =
|
||||
file.type === "image/gif"
|
||||
? file
|
||||
: await compressImage(file, {
|
||||
: await ImageHelper.compress(file, {
|
||||
maxHeight: 64,
|
||||
maxWidth: 64,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { observable } from "mobx";
|
||||
import { makeObservable, observable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import type { TFunction } from "i18next";
|
||||
@@ -25,7 +25,7 @@ interface OwnProps {
|
||||
/** Whether to show a title heading. */
|
||||
showTitle?: boolean;
|
||||
/** The wrapping component to use. */
|
||||
component?: React.ComponentType | string;
|
||||
component?: React.ComponentType<React.PropsWithChildren> | string;
|
||||
/** Children rendered when no error is present. */
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ const ERROR_TRACKING_WINDOW_MS = 5 * 60 * 1000; // 5 minutes
|
||||
@observer
|
||||
class ErrorBoundaryClass extends React.Component<Props> {
|
||||
@observable
|
||||
error: Error | null | undefined;
|
||||
error: Error | null | undefined = undefined;
|
||||
|
||||
@observable
|
||||
showDetails = false;
|
||||
@@ -48,6 +48,11 @@ class ErrorBoundaryClass extends React.Component<Props> {
|
||||
@observable
|
||||
isRepeatedError = false;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.checkForPreviousErrors();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { ArchiveIcon, CodeIcon } from "outline-icons";
|
||||
import { ArchiveIcon, CodeIcon, GlobeIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
@@ -72,6 +72,12 @@ export const ExportDialog = observer(({ collection, onSubmit }: Props) => {
|
||||
value: FileOperationFormat.MarkdownZip,
|
||||
icon: <MarkdownIcon />,
|
||||
},
|
||||
{
|
||||
title: "Open Knowledge Format",
|
||||
extension: ".okf.zip",
|
||||
value: FileOperationFormat.OKFZip,
|
||||
icon: <GlobeIcon />,
|
||||
},
|
||||
{
|
||||
title: "HTML",
|
||||
extension: ".html.zip",
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ const FilterOptions = ({
|
||||
: "";
|
||||
|
||||
const renderItem = React.useCallback(
|
||||
(option) => {
|
||||
(option: TFilterOption) => {
|
||||
const handleClick = () => {
|
||||
onSelect(option.key);
|
||||
setOpen(false);
|
||||
|
||||
@@ -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);
|
||||
@@ -0,0 +1,86 @@
|
||||
import styled, { css } from "styled-components";
|
||||
import breakpoint from "styled-components-breakpoint";
|
||||
import { s } from "@shared/styles";
|
||||
import Flex from "~/components/Flex";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
|
||||
/** A dot separating two pieces of meta information. */
|
||||
export const Separator = styled.span`
|
||||
padding: 0 0.4em;
|
||||
|
||||
&::after {
|
||||
content: "•";
|
||||
}
|
||||
`;
|
||||
|
||||
/** A button that visually matches the surrounding meta text. */
|
||||
export const MetaButton = styled(NudeButton)`
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: 0;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: inherit;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
/** Lays out a line of meta information about a document or collection. */
|
||||
export const metaStyles = css<{ $rtl?: boolean }>`
|
||||
justify-content: ${(props) => (props.$rtl ? "flex-end" : "flex-start")};
|
||||
color: ${s("textTertiary")};
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
`;
|
||||
|
||||
/**
|
||||
* Additional styles for a line of meta information rendered directly beneath a
|
||||
* page title. Composed by `HeaderMeta`, and applied directly by consumers that
|
||||
* style an existing meta component rather than rendering their own.
|
||||
*/
|
||||
export const headerMetaStyles = css`
|
||||
margin: -12px 0 2em 0;
|
||||
font-size: 14px;
|
||||
position: relative;
|
||||
user-select: none;
|
||||
z-index: 1;
|
||||
|
||||
${breakpoint("mobile", "tablet")`
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
line-height: 1.6;
|
||||
|
||||
${Separator} {
|
||||
display: none;
|
||||
}
|
||||
`}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
cursor: var(--pointer);
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
display: none;
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* A line of meta information rendered directly beneath a page title, stacking
|
||||
* into a list on mobile and hidden when printing.
|
||||
*/
|
||||
export const HeaderMeta = styled(Flex)<{ $rtl?: boolean }>`
|
||||
${metaStyles}
|
||||
${headerMetaStyles}
|
||||
`;
|
||||
@@ -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,11 +24,12 @@ function InputSearch(
|
||||
onKeyDown,
|
||||
onBlur,
|
||||
onFocus,
|
||||
ref,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const handleFocus = React.useCallback(
|
||||
(event) => {
|
||||
(event: React.FocusEvent<HTMLInputElement>) => {
|
||||
setIsFocused(true);
|
||||
onFocus?.(event);
|
||||
},
|
||||
@@ -38,7 +37,7 @@ function InputSearch(
|
||||
);
|
||||
|
||||
const handleBlur = React.useCallback(
|
||||
(event) => {
|
||||
(event: React.FocusEvent<HTMLInputElement>) => {
|
||||
setIsFocused(false);
|
||||
onBlur?.(event);
|
||||
},
|
||||
@@ -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({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import styled, { css } from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import type { Option } from "~/components/InputSelect";
|
||||
@@ -9,56 +9,58 @@ 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")};
|
||||
${({ nude }) =>
|
||||
nude &&
|
||||
css`
|
||||
color: ${s("textSecondary")};
|
||||
`}
|
||||
${({ $shrink }) => !$shrink && "margin-bottom: 16px;"}
|
||||
`;
|
||||
+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")};
|
||||
|
||||
@@ -9,7 +9,7 @@ type Props = {
|
||||
/**
|
||||
* Asyncronously load required polyfills. Should wrap the React tree.
|
||||
*/
|
||||
export const LazyPolyfill: React.FC = ({ children }: Props) => {
|
||||
export const LazyPolyfill: React.FC<Props> = ({ children }: Props) => {
|
||||
const [isLoaded, setIsLoaded] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
||||
+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) {
|
||||
@@ -132,7 +128,7 @@ const ListItem = (
|
||||
as={NavLink}
|
||||
to={to}
|
||||
>
|
||||
{content}
|
||||
{(match) => content(!!match)}
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { action, computed, observable } from "mobx";
|
||||
import { action, computed, makeObservable, observable } from "mobx";
|
||||
|
||||
/**
|
||||
* Holds the ephemeral multi-selection state for a single list of models.
|
||||
@@ -10,6 +10,10 @@ import { action, computed, observable } from "mobx";
|
||||
export class ModelSelection {
|
||||
private ids = observable.set<string>();
|
||||
|
||||
constructor() {
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
/** Ordered identifiers of the list, used to resolve shift-click ranges. */
|
||||
private order: string[] = [];
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { LocationDescriptor, LocationDescriptorObject } from "history";
|
||||
import * as React from "react";
|
||||
import { type match, NavLink, Route } from "react-router-dom";
|
||||
|
||||
type Props = React.ComponentProps<typeof NavLink> & {
|
||||
type Props = Omit<React.ComponentProps<typeof NavLink>, "children"> & {
|
||||
children?: (
|
||||
match:
|
||||
| match<{
|
||||
@@ -18,12 +18,16 @@ type Props = React.ComponentProps<typeof NavLink> & {
|
||||
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);
|
||||
@@ -22,7 +22,7 @@ type Props = {
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
|
||||
const NotificationsPopover: React.FC = ({ children }: Props) => {
|
||||
const NotificationsPopover: React.FC<Props> = ({ children }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const { notifications } = useStores();
|
||||
const shouldOpen = isTruthyQueryValue(useConsumeQueryParam("notifications"));
|
||||
|
||||
@@ -5,33 +5,36 @@ import { InputSelect } from "../InputSelect";
|
||||
/**
|
||||
* An input that allows a choice of OAuth client type.
|
||||
*/
|
||||
export const InputClientType = React.forwardRef(
|
||||
(
|
||||
props: Omit<React.ComponentProps<typeof InputSelect>, "options" | "label">,
|
||||
ref: React.Ref<HTMLButtonElement>
|
||||
) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<InputSelect
|
||||
{...props}
|
||||
label={t("Client type")}
|
||||
ref={ref}
|
||||
style={{ marginBottom: "1em" }}
|
||||
options={[
|
||||
{
|
||||
type: "item",
|
||||
label: t("Confidential"),
|
||||
value: "confidential",
|
||||
description: t("Suitable for server-side applications"),
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: t("Public"),
|
||||
value: "public",
|
||||
description: t("Suitable for client-side or mobile applications"),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
export function InputClientType({
|
||||
ref,
|
||||
...props
|
||||
}: Omit<
|
||||
React.ComponentPropsWithoutRef<typeof InputSelect>,
|
||||
"options" | "label"
|
||||
> & {
|
||||
ref?: React.Ref<HTMLButtonElement>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<InputSelect
|
||||
{...props}
|
||||
label={t("Client type")}
|
||||
ref={ref}
|
||||
style={{ marginBottom: "1em" }}
|
||||
options={[
|
||||
{
|
||||
type: "item",
|
||||
label: t("Confidential"),
|
||||
value: "confidential",
|
||||
description: t("Suitable for server-side applications"),
|
||||
},
|
||||
{
|
||||
type: "item",
|
||||
label: t("Public"),
|
||||
value: "public",
|
||||
description: t("Suitable for client-side or mobile applications"),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -2,12 +2,18 @@ import { useEffect } from "react";
|
||||
import { useTheme } from "styled-components";
|
||||
import { light } from "@shared/styles/theme";
|
||||
|
||||
/**
|
||||
* Synchronizes browser page colors with the active application theme.
|
||||
*
|
||||
* @returns null.
|
||||
*/
|
||||
export default function PageTheme() {
|
||||
const theme = useTheme();
|
||||
const { background, isDark } = theme;
|
||||
|
||||
useEffect(() => {
|
||||
// theme-color adjusts the title bar color for desktop PWA
|
||||
const themeElement = document.querySelector('meta[name="theme-color"]');
|
||||
// theme-color adjusts the browser chrome for installed PWAs
|
||||
const themeElements = document.querySelectorAll('meta[name="theme-color"]');
|
||||
|
||||
// color-scheme controls user-agent controls, scrollbars and the page canvas
|
||||
const colorSchemeElement = document.querySelector(
|
||||
@@ -19,17 +25,19 @@ export default function PageTheme() {
|
||||
if (document.body) {
|
||||
document.body.style.background = background;
|
||||
}
|
||||
themeElement?.setAttribute("content", background);
|
||||
themeElements.forEach((element) => {
|
||||
element.setAttribute("content", background);
|
||||
});
|
||||
colorSchemeElement?.setAttribute("content", isDark ? "dark" : "light");
|
||||
};
|
||||
|
||||
applyTheme(theme.background, theme.isDark);
|
||||
applyTheme(background, isDark);
|
||||
|
||||
const handleChange = (event: MediaQueryListEvent) => {
|
||||
if (event.matches) {
|
||||
applyTheme(light.background, false);
|
||||
} else {
|
||||
applyTheme(theme.background, theme.isDark);
|
||||
applyTheme(background, isDark);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,7 +47,7 @@ export default function PageTheme() {
|
||||
const mediaQuery = window.matchMedia("print");
|
||||
mediaQuery.addEventListener("change", handleChange);
|
||||
return () => mediaQuery.removeEventListener("change", handleChange);
|
||||
}, [theme]);
|
||||
}, [background, isDark]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -92,6 +92,7 @@ function SearchActions() {
|
||||
keywords: searchQuery,
|
||||
analyticsName: "Open search result",
|
||||
section: SearchResultsSection,
|
||||
visible: ({ isMCP }) => !isMCP,
|
||||
priority: toActionPriority(index, results.length),
|
||||
icon: <SearchResultIcon document={result.document} />,
|
||||
badge: result.document.isArchived ? (
|
||||
|
||||
@@ -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);
|
||||
@@ -137,7 +137,7 @@ function SharePopover({
|
||||
}, [pendingIds, prevPendingIds]);
|
||||
|
||||
const handleQuery = React.useCallback(
|
||||
(event) => {
|
||||
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
showPicker();
|
||||
setQuery(event.target.value);
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@ import styled, { useTheme } from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { DocumentPermission } from "@shared/types";
|
||||
import type Document from "~/models/Document";
|
||||
import type User from "~/models/User";
|
||||
import type UserMembership from "~/models/UserMembership";
|
||||
import { GroupAvatar } from "~/components/Avatar";
|
||||
import InputMemberPermissionSelect from "~/components/InputMemberPermissionSelect";
|
||||
@@ -41,7 +42,7 @@ function DocumentMemberList({ document, invitedInSession }: Props) {
|
||||
const theme = useTheme();
|
||||
|
||||
const handleRemoveUser = React.useCallback(
|
||||
async (item) => {
|
||||
async (item: User) => {
|
||||
try {
|
||||
await userMemberships.delete({
|
||||
documentId: document.id,
|
||||
@@ -65,7 +66,7 @@ function DocumentMemberList({ document, invitedInSession }: Props) {
|
||||
);
|
||||
|
||||
const handleUpdateUser = React.useCallback(
|
||||
async (userToUpdate, permission) => {
|
||||
async (userToUpdate: User, permission: DocumentPermission) => {
|
||||
try {
|
||||
await userMemberships.create({
|
||||
documentId: document.id,
|
||||
|
||||
@@ -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);
|
||||
@@ -253,7 +253,7 @@ function SharePopover({
|
||||
);
|
||||
|
||||
const handleQuery = React.useCallback(
|
||||
(event) => {
|
||||
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
showPicker();
|
||||
setQuery(event.target.value);
|
||||
},
|
||||
|
||||
Loaded 100 of 629 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user