mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 22:53:08 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b4a02e94a |
@@ -17,7 +17,6 @@
|
|||||||
"@emoji-mart/react": "^1.1.1",
|
"@emoji-mart/react": "^1.1.1",
|
||||||
"@excalidraw/excalidraw": "0.18.0-864353b",
|
"@excalidraw/excalidraw": "0.18.0-864353b",
|
||||||
"@mantine/core": "^8.1.3",
|
"@mantine/core": "^8.1.3",
|
||||||
"@mantine/dates": "^8.3.2",
|
|
||||||
"@mantine/form": "^8.1.3",
|
"@mantine/form": "^8.1.3",
|
||||||
"@mantine/hooks": "^8.1.3",
|
"@mantine/hooks": "^8.1.3",
|
||||||
"@mantine/modals": "^8.1.3",
|
"@mantine/modals": "^8.1.3",
|
||||||
|
|||||||
@@ -380,7 +380,6 @@
|
|||||||
"Real-time editor connection lost. Retrying...": "Real-time editor connection lost. Retrying...",
|
"Real-time editor connection lost. Retrying...": "Real-time editor connection lost. Retrying...",
|
||||||
"Table of contents": "Table of contents",
|
"Table of contents": "Table of contents",
|
||||||
"Add headings (H1, H2, H3) to generate a table of contents.": "Add headings (H1, H2, H3) to generate a table of contents.",
|
"Add headings (H1, H2, H3) to generate a table of contents.": "Add headings (H1, H2, H3) to generate a table of contents.",
|
||||||
"No table of contents yet": "No table of contents yet",
|
|
||||||
"Share": "Share",
|
"Share": "Share",
|
||||||
"Public sharing": "Public sharing",
|
"Public sharing": "Public sharing",
|
||||||
"Shared by": "Shared by",
|
"Shared by": "Shared by",
|
||||||
@@ -534,26 +533,5 @@
|
|||||||
"Remove image": "Remove image",
|
"Remove image": "Remove image",
|
||||||
"Failed to remove image": "Failed to remove image",
|
"Failed to remove image": "Failed to remove image",
|
||||||
"Image exceeds 10MB limit.": "Image exceeds 10MB limit.",
|
"Image exceeds 10MB limit.": "Image exceeds 10MB limit.",
|
||||||
"Image removed successfully": "Image removed successfully",
|
"Image removed successfully": "Image removed successfully"
|
||||||
"API key": "API key",
|
|
||||||
"API key created successfully": "API key created successfully",
|
|
||||||
"API keys": "API keys",
|
|
||||||
"API management": "API management",
|
|
||||||
"Are you sure you want to revoke this API key": "Are you sure you want to revoke this API key",
|
|
||||||
"Create API Key": "Create API Key",
|
|
||||||
"Custom expiration date": "Custom expiration date",
|
|
||||||
"Enter a descriptive token name": "Enter a descriptive token name",
|
|
||||||
"Expiration": "Expiration",
|
|
||||||
"Expired": "Expired",
|
|
||||||
"Expires": "Expires",
|
|
||||||
"I've saved my API key": "I've saved my API key",
|
|
||||||
"Last use": "Last Used",
|
|
||||||
"No API keys found": "No API keys found",
|
|
||||||
"No expiration": "No expiration",
|
|
||||||
"Revoke API key": "Revoke API key",
|
|
||||||
"Revoked successfully": "Revoked successfully",
|
|
||||||
"Select expiration date": "Select expiration date",
|
|
||||||
"This action cannot be undone. Any applications using this API key will stop working.": "This action cannot be undone. Any applications using this API key will stop working.",
|
|
||||||
"Update API key": "Update API key",
|
|
||||||
"Manage API keys for all users in the workspace": "Manage API keys for all users in the workspace"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ import SpacesPage from "@/pages/spaces/spaces.tsx";
|
|||||||
import { MfaChallengePage } from "@/ee/mfa/pages/mfa-challenge-page";
|
import { MfaChallengePage } from "@/ee/mfa/pages/mfa-challenge-page";
|
||||||
import { MfaSetupRequiredPage } from "@/ee/mfa/pages/mfa-setup-required-page";
|
import { MfaSetupRequiredPage } from "@/ee/mfa/pages/mfa-setup-required-page";
|
||||||
import SpaceTrash from "@/pages/space/space-trash.tsx";
|
import SpaceTrash from "@/pages/space/space-trash.tsx";
|
||||||
import UserApiKeys from "@/ee/api-key/pages/user-api-keys";
|
|
||||||
import WorkspaceApiKeys from "@/ee/api-key/pages/workspace-api-keys";
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -98,10 +96,8 @@ export default function App() {
|
|||||||
path={"account/preferences"}
|
path={"account/preferences"}
|
||||||
element={<AccountPreferences />}
|
element={<AccountPreferences />}
|
||||||
/>
|
/>
|
||||||
<Route path={"account/api-keys"} element={<UserApiKeys />} />
|
|
||||||
<Route path={"workspace"} element={<WorkspaceSettings />} />
|
<Route path={"workspace"} element={<WorkspaceSettings />} />
|
||||||
<Route path={"members"} element={<WorkspaceMembers />} />
|
<Route path={"members"} element={<WorkspaceMembers />} />
|
||||||
<Route path={"api-keys"} element={<WorkspaceApiKeys />} />
|
|
||||||
<Route path={"groups"} element={<Groups />} />
|
<Route path={"groups"} element={<Groups />} />
|
||||||
<Route path={"groups/:groupId"} element={<GroupInfo />} />
|
<Route path={"groups/:groupId"} element={<GroupInfo />} />
|
||||||
<Route path={"spaces"} element={<Spaces />} />
|
<Route path={"spaces"} element={<Spaces />} />
|
||||||
|
|||||||
@@ -4,15 +4,14 @@ import { useTranslation } from "react-i18next";
|
|||||||
|
|
||||||
interface NoTableResultsProps {
|
interface NoTableResultsProps {
|
||||||
colSpan: number;
|
colSpan: number;
|
||||||
text?: string;
|
|
||||||
}
|
}
|
||||||
export default function NoTableResults({ colSpan, text }: NoTableResultsProps) {
|
export default function NoTableResults({ colSpan }: NoTableResultsProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<Table.Tr>
|
<Table.Tr>
|
||||||
<Table.Td colSpan={colSpan}>
|
<Table.Td colSpan={colSpan}>
|
||||||
<Text fw={500} c="dimmed" ta="center">
|
<Text fw={500} c="dimmed" ta="center">
|
||||||
{text || t("No results found...")}
|
{t("No results found...")}
|
||||||
</Text>
|
</Text>
|
||||||
</Table.Td>
|
</Table.Td>
|
||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { getWorkspaceMembers } from "@/features/workspace/services/workspace-ser
|
|||||||
import { getLicenseInfo } from "@/ee/licence/services/license-service.ts";
|
import { getLicenseInfo } from "@/ee/licence/services/license-service.ts";
|
||||||
import { getSsoProviders } from "@/ee/security/services/security-service.ts";
|
import { getSsoProviders } from "@/ee/security/services/security-service.ts";
|
||||||
import { getShares } from "@/features/share/services/share-service.ts";
|
import { getShares } from "@/features/share/services/share-service.ts";
|
||||||
import { getApiKeys } from "@/ee/api-key";
|
|
||||||
|
|
||||||
export const prefetchWorkspaceMembers = () => {
|
export const prefetchWorkspaceMembers = () => {
|
||||||
const params = { limit: 100, page: 1, query: "" } as QueryParams;
|
const params = { limit: 100, page: 1, query: "" } as QueryParams;
|
||||||
@@ -66,17 +65,3 @@ export const prefetchShares = () => {
|
|||||||
queryFn: () => getShares({ page: 1, limit: 100 }),
|
queryFn: () => getShares({ page: 1, limit: 100 }),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const prefetchApiKeys = () => {
|
|
||||||
queryClient.prefetchQuery({
|
|
||||||
queryKey: ["api-key-list", { page: 1 }],
|
|
||||||
queryFn: () => getApiKeys({ page: 1 }),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const prefetchApiKeyManagement = () => {
|
|
||||||
queryClient.prefetchQuery({
|
|
||||||
queryKey: ["api-key-list", { page: 1 }],
|
|
||||||
queryFn: () => getApiKeys({ page: 1, adminView: true }),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import useUserRole from "@/hooks/use-user-role.tsx";
|
|||||||
import { useAtom } from "jotai/index";
|
import { useAtom } from "jotai/index";
|
||||||
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
import {
|
import {
|
||||||
prefetchApiKeyManagement,
|
|
||||||
prefetchApiKeys,
|
|
||||||
prefetchBilling,
|
prefetchBilling,
|
||||||
prefetchGroups,
|
prefetchGroups,
|
||||||
prefetchLicense,
|
prefetchLicense,
|
||||||
@@ -62,14 +60,6 @@ const groupedData: DataGroup[] = [
|
|||||||
icon: IconBrush,
|
icon: IconBrush,
|
||||||
path: "/settings/account/preferences",
|
path: "/settings/account/preferences",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: "API keys",
|
|
||||||
icon: IconKey,
|
|
||||||
path: "/settings/account/api-keys",
|
|
||||||
isCloud: true,
|
|
||||||
isEnterprise: true,
|
|
||||||
showDisabledInNonEE: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -100,15 +90,6 @@ const groupedData: DataGroup[] = [
|
|||||||
{ label: "Groups", icon: IconUsersGroup, path: "/settings/groups" },
|
{ label: "Groups", icon: IconUsersGroup, path: "/settings/groups" },
|
||||||
{ label: "Spaces", icon: IconSpaces, path: "/settings/spaces" },
|
{ label: "Spaces", icon: IconSpaces, path: "/settings/spaces" },
|
||||||
{ label: "Public sharing", icon: IconWorld, path: "/settings/sharing" },
|
{ label: "Public sharing", icon: IconWorld, path: "/settings/sharing" },
|
||||||
{
|
|
||||||
label: "API management",
|
|
||||||
icon: IconKey,
|
|
||||||
path: "/settings/api-keys",
|
|
||||||
isCloud: true,
|
|
||||||
isEnterprise: true,
|
|
||||||
isAdmin: true,
|
|
||||||
showDisabledInNonEE: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -214,12 +195,6 @@ export default function SettingsSidebar() {
|
|||||||
case "Public sharing":
|
case "Public sharing":
|
||||||
prefetchHandler = prefetchShares;
|
prefetchHandler = prefetchShares;
|
||||||
break;
|
break;
|
||||||
case "API keys":
|
|
||||||
prefetchHandler = prefetchApiKeys;
|
|
||||||
break;
|
|
||||||
case "API management":
|
|
||||||
prefetchHandler = prefetchApiKeyManagement;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import {
|
|
||||||
Modal,
|
|
||||||
Text,
|
|
||||||
Stack,
|
|
||||||
Alert,
|
|
||||||
Group,
|
|
||||||
Button,
|
|
||||||
TextInput,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
import CopyTextButton from "@/components/common/copy.tsx";
|
|
||||||
|
|
||||||
interface ApiKeyCreatedModalProps {
|
|
||||||
opened: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
apiKey: IApiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ApiKeyCreatedModal({
|
|
||||||
opened,
|
|
||||||
onClose,
|
|
||||||
apiKey,
|
|
||||||
}: ApiKeyCreatedModalProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
if (!apiKey) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
opened={opened}
|
|
||||||
onClose={onClose}
|
|
||||||
title={t("API key created")}
|
|
||||||
size="lg"
|
|
||||||
>
|
|
||||||
<Stack gap="md">
|
|
||||||
<Alert
|
|
||||||
icon={<IconAlertTriangle size={16} />}
|
|
||||||
title={t("Important")}
|
|
||||||
color="red"
|
|
||||||
>
|
|
||||||
{t(
|
|
||||||
"Make sure to copy your API key now. You won't be able to see it again!",
|
|
||||||
)}
|
|
||||||
</Alert>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Text size="sm" fw={500} mb="xs">
|
|
||||||
{t("API key")}
|
|
||||||
</Text>
|
|
||||||
<Group gap="xs" wrap="nowrap">
|
|
||||||
<TextInput
|
|
||||||
variant="filled"
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
}}
|
|
||||||
value={apiKey.token}
|
|
||||||
readOnly
|
|
||||||
/>
|
|
||||||
|
|
||||||
<CopyTextButton text={apiKey.token} />
|
|
||||||
</Group>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button fullWidth onClick={onClose} mt="md">
|
|
||||||
{t("I've saved my API key")}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
import { ActionIcon, Group, Menu, Table, Text } from "@mantine/core";
|
|
||||||
import { IconDots, IconEdit, IconTrash } from "@tabler/icons-react";
|
|
||||||
import { format } from "date-fns";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
|
||||||
import React from "react";
|
|
||||||
import NoTableResults from "@/components/common/no-table-results";
|
|
||||||
|
|
||||||
interface ApiKeyTableProps {
|
|
||||||
apiKeys: IApiKey[];
|
|
||||||
isLoading?: boolean;
|
|
||||||
showUserColumn?: boolean;
|
|
||||||
onUpdate?: (apiKey: IApiKey) => void;
|
|
||||||
onRevoke?: (apiKey: IApiKey) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ApiKeyTable({
|
|
||||||
apiKeys,
|
|
||||||
isLoading,
|
|
||||||
showUserColumn = false,
|
|
||||||
onUpdate,
|
|
||||||
onRevoke,
|
|
||||||
}: ApiKeyTableProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const formatDate = (date: Date | string | null) => {
|
|
||||||
if (!date) return t("Never");
|
|
||||||
return format(new Date(date), "MMM dd, yyyy");
|
|
||||||
};
|
|
||||||
|
|
||||||
const isExpired = (expiresAt: string | null) => {
|
|
||||||
if (!expiresAt) return false;
|
|
||||||
return new Date(expiresAt) < new Date();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.ScrollContainer minWidth={500}>
|
|
||||||
<Table highlightOnHover verticalSpacing="sm">
|
|
||||||
<Table.Thead>
|
|
||||||
<Table.Tr>
|
|
||||||
<Table.Th>{t("Name")}</Table.Th>
|
|
||||||
{showUserColumn && <Table.Th>{t("User")}</Table.Th>}
|
|
||||||
<Table.Th>{t("Last used")}</Table.Th>
|
|
||||||
<Table.Th>{t("Expires")}</Table.Th>
|
|
||||||
<Table.Th>{t("Created")}</Table.Th>
|
|
||||||
<Table.Th></Table.Th>
|
|
||||||
</Table.Tr>
|
|
||||||
</Table.Thead>
|
|
||||||
|
|
||||||
<Table.Tbody>
|
|
||||||
{apiKeys && apiKeys.length > 0 ? (
|
|
||||||
apiKeys.map((apiKey: IApiKey, index: number) => (
|
|
||||||
<Table.Tr key={index}>
|
|
||||||
<Table.Td>
|
|
||||||
<Text fz="sm" fw={500}>
|
|
||||||
{apiKey.name}
|
|
||||||
</Text>
|
|
||||||
</Table.Td>
|
|
||||||
|
|
||||||
{showUserColumn && apiKey.creator && (
|
|
||||||
<Table.Td>
|
|
||||||
<Group gap="4" wrap="nowrap">
|
|
||||||
<CustomAvatar
|
|
||||||
avatarUrl={apiKey.creator?.avatarUrl}
|
|
||||||
name={apiKey.creator.name}
|
|
||||||
size="sm"
|
|
||||||
/>
|
|
||||||
<Text fz="sm" lineClamp={1}>
|
|
||||||
{apiKey.creator.name}
|
|
||||||
</Text>
|
|
||||||
</Group>
|
|
||||||
</Table.Td>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Table.Td>
|
|
||||||
<Text fz="sm" style={{ whiteSpace: "nowrap" }}>
|
|
||||||
{formatDate(apiKey.lastUsedAt)}
|
|
||||||
</Text>
|
|
||||||
</Table.Td>
|
|
||||||
|
|
||||||
<Table.Td>
|
|
||||||
{apiKey.expiresAt ? (
|
|
||||||
isExpired(apiKey.expiresAt) ? (
|
|
||||||
<Text fz="sm" style={{ whiteSpace: "nowrap" }}>
|
|
||||||
{t("Expired")}
|
|
||||||
</Text>
|
|
||||||
) : (
|
|
||||||
<Text fz="sm" style={{ whiteSpace: "nowrap" }}>
|
|
||||||
{formatDate(apiKey.expiresAt)}
|
|
||||||
</Text>
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<Text fz="sm" style={{ whiteSpace: "nowrap" }}>
|
|
||||||
{t("Never")}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</Table.Td>
|
|
||||||
|
|
||||||
<Table.Td>
|
|
||||||
<Text fz="sm" style={{ whiteSpace: "nowrap" }}>
|
|
||||||
{formatDate(apiKey.createdAt)}
|
|
||||||
</Text>
|
|
||||||
</Table.Td>
|
|
||||||
|
|
||||||
<Table.Td>
|
|
||||||
<Menu position="bottom-end" withinPortal>
|
|
||||||
<Menu.Target>
|
|
||||||
<ActionIcon variant="subtle" color="gray">
|
|
||||||
<IconDots size={16} />
|
|
||||||
</ActionIcon>
|
|
||||||
</Menu.Target>
|
|
||||||
<Menu.Dropdown>
|
|
||||||
{onUpdate && (
|
|
||||||
<Menu.Item
|
|
||||||
leftSection={<IconEdit size={16} />}
|
|
||||||
onClick={() => onUpdate(apiKey)}
|
|
||||||
>
|
|
||||||
{t("Rename")}
|
|
||||||
</Menu.Item>
|
|
||||||
)}
|
|
||||||
{onRevoke && (
|
|
||||||
<Menu.Item
|
|
||||||
leftSection={<IconTrash size={16} />}
|
|
||||||
color="red"
|
|
||||||
onClick={() => onRevoke(apiKey)}
|
|
||||||
>
|
|
||||||
{t("Revoke")}
|
|
||||||
</Menu.Item>
|
|
||||||
)}
|
|
||||||
</Menu.Dropdown>
|
|
||||||
</Menu>
|
|
||||||
</Table.Td>
|
|
||||||
</Table.Tr>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<NoTableResults colSpan={showUserColumn ? 6 : 5} />
|
|
||||||
)}
|
|
||||||
</Table.Tbody>
|
|
||||||
</Table>
|
|
||||||
</Table.ScrollContainer>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
import { lazy, Suspense, useState } from "react";
|
|
||||||
import { Modal, TextInput, Button, Group, Stack, Select } from "@mantine/core";
|
|
||||||
import { useForm } from "@mantine/form";
|
|
||||||
import { zodResolver } from "mantine-form-zod-resolver";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useCreateApiKeyMutation } from "@/ee/api-key/queries/api-key-query";
|
|
||||||
import { IconCalendar } from "@tabler/icons-react";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
|
|
||||||
const DateInput = lazy(() =>
|
|
||||||
import("@mantine/dates").then((module) => ({
|
|
||||||
default: module.DateInput,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
|
|
||||||
interface CreateApiKeyModalProps {
|
|
||||||
opened: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
onSuccess: (response: IApiKey) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const formSchema = z.object({
|
|
||||||
name: z.string().min(1, "Name is required"),
|
|
||||||
expiresAt: z.string().optional(),
|
|
||||||
});
|
|
||||||
type FormValues = z.infer<typeof formSchema>;
|
|
||||||
|
|
||||||
export function CreateApiKeyModal({
|
|
||||||
opened,
|
|
||||||
onClose,
|
|
||||||
onSuccess,
|
|
||||||
}: CreateApiKeyModalProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [expirationOption, setExpirationOption] = useState<string>("30");
|
|
||||||
const createApiKeyMutation = useCreateApiKeyMutation();
|
|
||||||
|
|
||||||
const form = useForm<FormValues>({
|
|
||||||
validate: zodResolver(formSchema),
|
|
||||||
initialValues: {
|
|
||||||
name: "",
|
|
||||||
expiresAt: "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getExpirationDate = (): string | undefined => {
|
|
||||||
if (expirationOption === "never") {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (expirationOption === "custom") {
|
|
||||||
return form.values.expiresAt;
|
|
||||||
}
|
|
||||||
const days = parseInt(expirationOption);
|
|
||||||
const date = new Date();
|
|
||||||
date.setDate(date.getDate() + days);
|
|
||||||
return date.toISOString();
|
|
||||||
};
|
|
||||||
|
|
||||||
const getExpirationLabel = (days: number) => {
|
|
||||||
const date = new Date();
|
|
||||||
date.setDate(date.getDate() + days);
|
|
||||||
const formatted = date.toLocaleDateString("en-US", {
|
|
||||||
month: "short",
|
|
||||||
day: "2-digit",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
return `${days} days (${formatted})`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const expirationOptions = [
|
|
||||||
{ value: "30", label: getExpirationLabel(30) },
|
|
||||||
{ value: "60", label: getExpirationLabel(60) },
|
|
||||||
{ value: "90", label: getExpirationLabel(90) },
|
|
||||||
{ value: "365", label: getExpirationLabel(365) },
|
|
||||||
{ value: "custom", label: t("Custom") },
|
|
||||||
{ value: "never", label: t("No expiration") },
|
|
||||||
];
|
|
||||||
|
|
||||||
const handleSubmit = async (data: {
|
|
||||||
name?: string;
|
|
||||||
expiresAt?: string | Date;
|
|
||||||
}) => {
|
|
||||||
const groupData = {
|
|
||||||
name: data.name,
|
|
||||||
expiresAt: getExpirationDate(),
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const createdKey = await createApiKeyMutation.mutateAsync(groupData);
|
|
||||||
onSuccess(createdKey);
|
|
||||||
form.reset();
|
|
||||||
onClose();
|
|
||||||
} catch (err) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
form.reset();
|
|
||||||
setExpirationOption("30");
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
opened={opened}
|
|
||||||
onClose={handleClose}
|
|
||||||
title={t("Create API Key")}
|
|
||||||
size="md"
|
|
||||||
>
|
|
||||||
<form onSubmit={form.onSubmit((values) => handleSubmit(values))}>
|
|
||||||
<Stack gap="md">
|
|
||||||
<TextInput
|
|
||||||
label={t("Name")}
|
|
||||||
placeholder={t("Enter a descriptive name")}
|
|
||||||
data-autofocus
|
|
||||||
required
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Select
|
|
||||||
label={t("Expiration")}
|
|
||||||
data={expirationOptions}
|
|
||||||
value={expirationOption}
|
|
||||||
onChange={(value) => setExpirationOption(value || "30")}
|
|
||||||
leftSection={<IconCalendar size={16} />}
|
|
||||||
allowDeselect={false}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{expirationOption === "custom" && (
|
|
||||||
<Suspense fallback={null}>
|
|
||||||
<DateInput
|
|
||||||
label={t("Custom expiration date")}
|
|
||||||
placeholder={t("Select expiration date")}
|
|
||||||
minDate={new Date()}
|
|
||||||
{...form.getInputProps("expiresAt")}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Group justify="flex-end" mt="md">
|
|
||||||
<Button variant="default" onClick={handleClose}>
|
|
||||||
{t("Cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" loading={createApiKeyMutation.isPending}>
|
|
||||||
{t("Create")}
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
import { Modal, Text, Button, Group, Stack } from "@mantine/core";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
import { useRevokeApiKeyMutation } from "@/ee/api-key/queries/api-key-query.ts";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
|
|
||||||
interface RevokeApiKeyModalProps {
|
|
||||||
opened: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
apiKey: IApiKey | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function RevokeApiKeyModal({
|
|
||||||
opened,
|
|
||||||
onClose,
|
|
||||||
apiKey,
|
|
||||||
}: RevokeApiKeyModalProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const revokeApiKeyMutation = useRevokeApiKeyMutation();
|
|
||||||
|
|
||||||
const handleRevoke = async () => {
|
|
||||||
if (!apiKey) return;
|
|
||||||
await revokeApiKeyMutation.mutateAsync({
|
|
||||||
apiKeyId: apiKey.id,
|
|
||||||
});
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
opened={opened}
|
|
||||||
onClose={onClose}
|
|
||||||
title={t("Revoke API key")}
|
|
||||||
size="md"
|
|
||||||
>
|
|
||||||
<Stack gap="md">
|
|
||||||
<Text>
|
|
||||||
{t("Are you sure you want to revoke this API key")}{" "}
|
|
||||||
<strong>{apiKey?.name}</strong>?
|
|
||||||
</Text>
|
|
||||||
<Text size="sm" c="dimmed">
|
|
||||||
{t(
|
|
||||||
"This action cannot be undone. Any applications using this API key will stop working.",
|
|
||||||
)}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Group justify="flex-end" mt="md">
|
|
||||||
<Button variant="default" onClick={onClose}>
|
|
||||||
{t("Cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
color="red"
|
|
||||||
onClick={handleRevoke}
|
|
||||||
loading={revokeApiKeyMutation.isPending}
|
|
||||||
>
|
|
||||||
{t("Revoke")}
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
import { Modal, TextInput, Button, Group, Stack } from "@mantine/core";
|
|
||||||
import { useForm } from "@mantine/form";
|
|
||||||
import { zodResolver } from "mantine-form-zod-resolver";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useUpdateApiKeyMutation } from "@/ee/api-key/queries/api-key-query";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
|
|
||||||
const formSchema = z.object({
|
|
||||||
name: z.string().min(1, "Name is required"),
|
|
||||||
});
|
|
||||||
type FormValues = z.infer<typeof formSchema>;
|
|
||||||
|
|
||||||
interface UpdateApiKeyModalProps {
|
|
||||||
opened: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
apiKey: IApiKey | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UpdateApiKeyModal({
|
|
||||||
opened,
|
|
||||||
onClose,
|
|
||||||
apiKey,
|
|
||||||
}: UpdateApiKeyModalProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const updateApiKeyMutation = useUpdateApiKeyMutation();
|
|
||||||
|
|
||||||
const form = useForm<FormValues>({
|
|
||||||
validate: zodResolver(formSchema),
|
|
||||||
initialValues: {
|
|
||||||
name: "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (opened && apiKey) {
|
|
||||||
form.setValues({ name: apiKey.name });
|
|
||||||
}
|
|
||||||
}, [opened, apiKey]);
|
|
||||||
|
|
||||||
const handleSubmit = async (data: { name?: string }) => {
|
|
||||||
const apiKeyData = {
|
|
||||||
apiKeyId: apiKey.id,
|
|
||||||
name: data.name,
|
|
||||||
};
|
|
||||||
|
|
||||||
await updateApiKeyMutation.mutateAsync(apiKeyData);
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
opened={opened}
|
|
||||||
onClose={onClose}
|
|
||||||
title={t("Update API key")}
|
|
||||||
size="md"
|
|
||||||
>
|
|
||||||
<form onSubmit={form.onSubmit((values) => handleSubmit(values))}>
|
|
||||||
<Stack gap="md">
|
|
||||||
<TextInput
|
|
||||||
label={t("Name")}
|
|
||||||
placeholder={t("Enter a descriptive token name")}
|
|
||||||
required
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Group justify="flex-end" mt="md">
|
|
||||||
<Button variant="default" onClick={onClose}>
|
|
||||||
{t("Cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" loading={updateApiKeyMutation.isPending}>
|
|
||||||
{t("Update")}
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
export { ApiKeyTable } from "./components/api-key-table";
|
|
||||||
export { CreateApiKeyModal } from "./components/create-api-key-modal";
|
|
||||||
export { ApiKeyCreatedModal } from "./components/api-key-created-modal";
|
|
||||||
export { UpdateApiKeyModal } from "./components/update-api-key-modal";
|
|
||||||
export { RevokeApiKeyModal } from "./components/revoke-api-key-modal";
|
|
||||||
|
|
||||||
// Services
|
|
||||||
export * from "./services/api-key-service";
|
|
||||||
|
|
||||||
// Types
|
|
||||||
export * from "./types/api-key.types";
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
import React, { useState } from "react";
|
|
||||||
import { Button, Group, Space } from "@mantine/core";
|
|
||||||
import { Helmet } from "react-helmet-async";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import SettingsTitle from "@/components/settings/settings-title";
|
|
||||||
import { getAppName } from "@/lib/config";
|
|
||||||
import { ApiKeyTable } from "@/ee/api-key/components/api-key-table";
|
|
||||||
import { CreateApiKeyModal } from "@/ee/api-key/components/create-api-key-modal";
|
|
||||||
import { ApiKeyCreatedModal } from "@/ee/api-key/components/api-key-created-modal";
|
|
||||||
import { UpdateApiKeyModal } from "@/ee/api-key/components/update-api-key-modal";
|
|
||||||
import { RevokeApiKeyModal } from "@/ee/api-key/components/revoke-api-key-modal";
|
|
||||||
import Paginate from "@/components/common/paginate";
|
|
||||||
import { usePaginateAndSearch } from "@/hooks/use-paginate-and-search";
|
|
||||||
import { useGetApiKeysQuery } from "@/ee/api-key/queries/api-key-query.ts";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
|
|
||||||
export default function UserApiKeys() {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { page, setPage } = usePaginateAndSearch();
|
|
||||||
const [createModalOpened, setCreateModalOpened] = useState(false);
|
|
||||||
const [createdApiKey, setCreatedApiKey] = useState<IApiKey | null>(null);
|
|
||||||
const [updateModalOpened, setUpdateModalOpened] = useState(false);
|
|
||||||
const [revokeModalOpened, setRevokeModalOpened] = useState(false);
|
|
||||||
const [selectedApiKey, setSelectedApiKey] = useState<IApiKey | null>(null);
|
|
||||||
const { data, isLoading } = useGetApiKeysQuery({ page });
|
|
||||||
|
|
||||||
const handleCreateSuccess = (response: IApiKey) => {
|
|
||||||
setCreatedApiKey(response);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpdate = (apiKey: IApiKey) => {
|
|
||||||
setSelectedApiKey(apiKey);
|
|
||||||
setUpdateModalOpened(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRevoke = (apiKey: IApiKey) => {
|
|
||||||
setSelectedApiKey(apiKey);
|
|
||||||
setRevokeModalOpened(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Helmet>
|
|
||||||
<title>
|
|
||||||
{t("API keys")} - {getAppName()}
|
|
||||||
</title>
|
|
||||||
</Helmet>
|
|
||||||
|
|
||||||
<SettingsTitle title={t("API keys")} />
|
|
||||||
|
|
||||||
<Group justify="flex-end" mb="md">
|
|
||||||
<Button onClick={() => setCreateModalOpened(true)}>
|
|
||||||
{t("Create API Key")}
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
|
|
||||||
<ApiKeyTable
|
|
||||||
apiKeys={data?.items || []}
|
|
||||||
isLoading={isLoading}
|
|
||||||
onUpdate={handleUpdate}
|
|
||||||
onRevoke={handleRevoke}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Space h="md" />
|
|
||||||
|
|
||||||
{data?.items.length > 0 && (
|
|
||||||
<Paginate
|
|
||||||
currentPage={page}
|
|
||||||
hasPrevPage={data?.meta.hasPrevPage}
|
|
||||||
hasNextPage={data?.meta.hasNextPage}
|
|
||||||
onPageChange={setPage}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<CreateApiKeyModal
|
|
||||||
opened={createModalOpened}
|
|
||||||
onClose={() => setCreateModalOpened(false)}
|
|
||||||
onSuccess={handleCreateSuccess}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ApiKeyCreatedModal
|
|
||||||
opened={!!createdApiKey}
|
|
||||||
onClose={() => setCreatedApiKey(null)}
|
|
||||||
apiKey={createdApiKey}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<UpdateApiKeyModal
|
|
||||||
opened={updateModalOpened}
|
|
||||||
onClose={() => {
|
|
||||||
setUpdateModalOpened(false);
|
|
||||||
setSelectedApiKey(null);
|
|
||||||
}}
|
|
||||||
apiKey={selectedApiKey}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<RevokeApiKeyModal
|
|
||||||
opened={revokeModalOpened}
|
|
||||||
onClose={() => {
|
|
||||||
setRevokeModalOpened(false);
|
|
||||||
setSelectedApiKey(null);
|
|
||||||
}}
|
|
||||||
apiKey={selectedApiKey}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
import React, { useState } from "react";
|
|
||||||
import { Button, Group, Space, Text } from "@mantine/core";
|
|
||||||
import { Helmet } from "react-helmet-async";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import SettingsTitle from "@/components/settings/settings-title";
|
|
||||||
import { getAppName } from "@/lib/config";
|
|
||||||
import { ApiKeyTable } from "@/ee/api-key/components/api-key-table";
|
|
||||||
import { CreateApiKeyModal } from "@/ee/api-key/components/create-api-key-modal";
|
|
||||||
import { ApiKeyCreatedModal } from "@/ee/api-key/components/api-key-created-modal";
|
|
||||||
import { UpdateApiKeyModal } from "@/ee/api-key/components/update-api-key-modal";
|
|
||||||
import { RevokeApiKeyModal } from "@/ee/api-key/components/revoke-api-key-modal";
|
|
||||||
import Paginate from "@/components/common/paginate";
|
|
||||||
import { usePaginateAndSearch } from "@/hooks/use-paginate-and-search";
|
|
||||||
import { useGetApiKeysQuery } from "@/ee/api-key/queries/api-key-query.ts";
|
|
||||||
import { IApiKey } from "@/ee/api-key";
|
|
||||||
import useUserRole from '@/hooks/use-user-role.tsx';
|
|
||||||
|
|
||||||
export default function WorkspaceApiKeys() {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { page, setPage } = usePaginateAndSearch();
|
|
||||||
const [createModalOpened, setCreateModalOpened] = useState(false);
|
|
||||||
const [createdApiKey, setCreatedApiKey] = useState<IApiKey | null>(null);
|
|
||||||
const [updateModalOpened, setUpdateModalOpened] = useState(false);
|
|
||||||
const [revokeModalOpened, setRevokeModalOpened] = useState(false);
|
|
||||||
const [selectedApiKey, setSelectedApiKey] = useState<IApiKey | null>(null);
|
|
||||||
const { data, isLoading } = useGetApiKeysQuery({ page, adminView: true });
|
|
||||||
const { isAdmin } = useUserRole();
|
|
||||||
|
|
||||||
if (!isAdmin) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCreateSuccess = (response: IApiKey) => {
|
|
||||||
setCreatedApiKey(response);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpdate = (apiKey: IApiKey) => {
|
|
||||||
setSelectedApiKey(apiKey);
|
|
||||||
setUpdateModalOpened(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRevoke = (apiKey: IApiKey) => {
|
|
||||||
setSelectedApiKey(apiKey);
|
|
||||||
setRevokeModalOpened(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Helmet>
|
|
||||||
<title>
|
|
||||||
{t("API management")} - {getAppName()}
|
|
||||||
</title>
|
|
||||||
</Helmet>
|
|
||||||
|
|
||||||
<SettingsTitle title={t("API management")} />
|
|
||||||
|
|
||||||
<Text size="md" c="dimmed" mb="md">
|
|
||||||
{t("Manage API keys for all users in the workspace")}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<Group justify="flex-end" mb="md">
|
|
||||||
<Button onClick={() => setCreateModalOpened(true)}>
|
|
||||||
{t("Create API Key")}
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
|
|
||||||
<ApiKeyTable
|
|
||||||
apiKeys={data?.items}
|
|
||||||
isLoading={isLoading}
|
|
||||||
showUserColumn
|
|
||||||
onUpdate={handleUpdate}
|
|
||||||
onRevoke={handleRevoke}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Space h="md" />
|
|
||||||
|
|
||||||
{data?.items.length > 0 && (
|
|
||||||
<Paginate
|
|
||||||
currentPage={page}
|
|
||||||
hasPrevPage={data?.meta.hasPrevPage}
|
|
||||||
hasNextPage={data?.meta.hasNextPage}
|
|
||||||
onPageChange={setPage}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<CreateApiKeyModal
|
|
||||||
opened={createModalOpened}
|
|
||||||
onClose={() => setCreateModalOpened(false)}
|
|
||||||
onSuccess={handleCreateSuccess}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ApiKeyCreatedModal
|
|
||||||
opened={!!createdApiKey}
|
|
||||||
onClose={() => setCreatedApiKey(null)}
|
|
||||||
apiKey={createdApiKey}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<UpdateApiKeyModal
|
|
||||||
opened={updateModalOpened}
|
|
||||||
onClose={() => {
|
|
||||||
setUpdateModalOpened(false);
|
|
||||||
setSelectedApiKey(null);
|
|
||||||
}}
|
|
||||||
apiKey={selectedApiKey}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<RevokeApiKeyModal
|
|
||||||
opened={revokeModalOpened}
|
|
||||||
onClose={() => {
|
|
||||||
setRevokeModalOpened(false);
|
|
||||||
setSelectedApiKey(null);
|
|
||||||
}}
|
|
||||||
apiKey={selectedApiKey}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import { IPagination, QueryParams } from "@/lib/types.ts";
|
|
||||||
import {
|
|
||||||
keepPreviousData,
|
|
||||||
useMutation,
|
|
||||||
useQuery,
|
|
||||||
useQueryClient,
|
|
||||||
UseQueryResult,
|
|
||||||
} from "@tanstack/react-query";
|
|
||||||
import {
|
|
||||||
createApiKey,
|
|
||||||
getApiKeys,
|
|
||||||
IApiKey,
|
|
||||||
ICreateApiKeyRequest,
|
|
||||||
IUpdateApiKeyRequest,
|
|
||||||
revokeApiKey,
|
|
||||||
updateApiKey,
|
|
||||||
} from "@/ee/api-key";
|
|
||||||
import { notifications } from "@mantine/notifications";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
export function useGetApiKeysQuery(
|
|
||||||
params?: QueryParams,
|
|
||||||
): UseQueryResult<IPagination<IApiKey>, Error> {
|
|
||||||
return useQuery({
|
|
||||||
queryKey: ["api-key-list", params],
|
|
||||||
queryFn: () => getApiKeys(params),
|
|
||||||
staleTime: 0,
|
|
||||||
gcTime: 0,
|
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useRevokeApiKeyMutation() {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation<
|
|
||||||
void,
|
|
||||||
Error,
|
|
||||||
{
|
|
||||||
apiKeyId: string;
|
|
||||||
}
|
|
||||||
>({
|
|
||||||
mutationFn: (data) => revokeApiKey(data),
|
|
||||||
onSuccess: (data, variables) => {
|
|
||||||
notifications.show({ message: t("Revoked successfully") });
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
predicate: (item) =>
|
|
||||||
["api-key-list"].includes(item.queryKey[0] as string),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
const errorMessage = error["response"]?.data?.message;
|
|
||||||
notifications.show({ message: errorMessage, color: "red" });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useCreateApiKeyMutation() {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation<IApiKey, Error, ICreateApiKeyRequest>({
|
|
||||||
mutationFn: (data) => createApiKey(data),
|
|
||||||
onSuccess: () => {
|
|
||||||
notifications.show({ message: t("API key created successfully") });
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
predicate: (item) =>
|
|
||||||
["api-key-list"].includes(item.queryKey[0] as string),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
const errorMessage = error["response"]?.data?.message;
|
|
||||||
notifications.show({ message: errorMessage, color: "red" });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useUpdateApiKeyMutation() {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation<IApiKey, Error, IUpdateApiKeyRequest>({
|
|
||||||
mutationFn: (data) => updateApiKey(data),
|
|
||||||
onSuccess: (data, variables) => {
|
|
||||||
notifications.show({ message: t("Updated successfully") });
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
predicate: (item) =>
|
|
||||||
["api-key-list"].includes(item.queryKey[0] as string),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
const errorMessage = error["response"]?.data?.message;
|
|
||||||
notifications.show({ message: errorMessage, color: "red" });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import api from "@/lib/api-client";
|
|
||||||
import {
|
|
||||||
ICreateApiKeyRequest,
|
|
||||||
IApiKey,
|
|
||||||
IUpdateApiKeyRequest,
|
|
||||||
} from "@/ee/api-key/types/api-key.types";
|
|
||||||
import { IPagination, QueryParams } from "@/lib/types.ts";
|
|
||||||
|
|
||||||
export async function getApiKeys(
|
|
||||||
params?: QueryParams,
|
|
||||||
): Promise<IPagination<IApiKey>> {
|
|
||||||
const req = await api.post("/api-keys", { ...params });
|
|
||||||
return req.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createApiKey(
|
|
||||||
data: ICreateApiKeyRequest,
|
|
||||||
): Promise<IApiKey> {
|
|
||||||
const req = await api.post<IApiKey>("/api-keys/create", data);
|
|
||||||
return req.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateApiKey(
|
|
||||||
data: IUpdateApiKeyRequest,
|
|
||||||
): Promise<IApiKey> {
|
|
||||||
const req = await api.post<IApiKey>("/api-keys/update", data);
|
|
||||||
return req.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function revokeApiKey(data: { apiKeyId: string }): Promise<void> {
|
|
||||||
await api.post("/api-keys/revoke", data);
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { IUser } from "@/features/user/types/user.types.ts";
|
|
||||||
|
|
||||||
export interface IApiKey {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
token?: string;
|
|
||||||
creatorId: string;
|
|
||||||
workspaceId: string;
|
|
||||||
expiresAt: string | null;
|
|
||||||
lastUsedAt: string | null;
|
|
||||||
createdAt: string;
|
|
||||||
creator: Partial<IUser>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ICreateApiKeyRequest {
|
|
||||||
name: string;
|
|
||||||
expiresAt?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IUpdateApiKeyRequest {
|
|
||||||
apiKeyId: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ import {
|
|||||||
BubbleMenuProps,
|
BubbleMenuProps,
|
||||||
isNodeSelection,
|
isNodeSelection,
|
||||||
useEditor,
|
useEditor,
|
||||||
useEditorState,
|
|
||||||
} from "@tiptap/react";
|
} from "@tiptap/react";
|
||||||
import { FC, useEffect, useRef, useState } from "react";
|
import { FC, useEffect, useRef, useState } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -51,52 +50,34 @@ export const EditorBubbleMenu: FC<EditorBubbleMenuProps> = (props) => {
|
|||||||
showCommentPopupRef.current = showCommentPopup;
|
showCommentPopupRef.current = showCommentPopup;
|
||||||
}, [showCommentPopup]);
|
}, [showCommentPopup]);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor: props.editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!props.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
isBold: ctx.editor.isActive("bold"),
|
|
||||||
isItalic: ctx.editor.isActive("italic"),
|
|
||||||
isUnderline: ctx.editor.isActive("underline"),
|
|
||||||
isStrike: ctx.editor.isActive("strike"),
|
|
||||||
isCode: ctx.editor.isActive("code"),
|
|
||||||
isComment: ctx.editor.isActive("comment"),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const items: BubbleMenuItem[] = [
|
const items: BubbleMenuItem[] = [
|
||||||
{
|
{
|
||||||
name: "Bold",
|
name: "Bold",
|
||||||
isActive: () => editorState?.isBold,
|
isActive: () => props.editor.isActive("bold"),
|
||||||
command: () => props.editor.chain().focus().toggleBold().run(),
|
command: () => props.editor.chain().focus().toggleBold().run(),
|
||||||
icon: IconBold,
|
icon: IconBold,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Italic",
|
name: "Italic",
|
||||||
isActive: () => editorState?.isItalic,
|
isActive: () => props.editor.isActive("italic"),
|
||||||
command: () => props.editor.chain().focus().toggleItalic().run(),
|
command: () => props.editor.chain().focus().toggleItalic().run(),
|
||||||
icon: IconItalic,
|
icon: IconItalic,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Underline",
|
name: "Underline",
|
||||||
isActive: () => editorState?.isUnderline,
|
isActive: () => props.editor.isActive("underline"),
|
||||||
command: () => props.editor.chain().focus().toggleUnderline().run(),
|
command: () => props.editor.chain().focus().toggleUnderline().run(),
|
||||||
icon: IconUnderline,
|
icon: IconUnderline,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Strike",
|
name: "Strike",
|
||||||
isActive: () => editorState?.isStrike,
|
isActive: () => props.editor.isActive("strike"),
|
||||||
command: () => props.editor.chain().focus().toggleStrike().run(),
|
command: () => props.editor.chain().focus().toggleStrike().run(),
|
||||||
icon: IconStrikethrough,
|
icon: IconStrikethrough,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Code",
|
name: "Code",
|
||||||
isActive: () => editorState?.isCode,
|
isActive: () => props.editor.isActive("code"),
|
||||||
command: () => props.editor.chain().focus().toggleCode().run(),
|
command: () => props.editor.chain().focus().toggleCode().run(),
|
||||||
icon: IconCode,
|
icon: IconCode,
|
||||||
},
|
},
|
||||||
@@ -104,7 +85,7 @@ export const EditorBubbleMenu: FC<EditorBubbleMenuProps> = (props) => {
|
|||||||
|
|
||||||
const commentItem: BubbleMenuItem = {
|
const commentItem: BubbleMenuItem = {
|
||||||
name: "Comment",
|
name: "Comment",
|
||||||
isActive: () => editorState?.isComment,
|
isActive: () => props.editor.isActive("comment"),
|
||||||
command: () => {
|
command: () => {
|
||||||
const commentId = uuid7();
|
const commentId = uuid7();
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import type { Editor } from "@tiptap/react";
|
import { useEditor } from "@tiptap/react";
|
||||||
import { useEditorState } from "@tiptap/react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export interface BubbleColorMenuItem {
|
export interface BubbleColorMenuItem {
|
||||||
@@ -19,7 +18,7 @@ export interface BubbleColorMenuItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ColorSelectorProps {
|
interface ColorSelectorProps {
|
||||||
editor: Editor | null;
|
editor: ReturnType<typeof useEditor>;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
@@ -109,36 +108,12 @@ export const ColorSelector: FC<ColorSelectorProps> = ({
|
|||||||
setIsOpen,
|
setIsOpen,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: ctx => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const activeColors: Record<string, boolean> = {};
|
|
||||||
TEXT_COLORS.forEach(({ color }) => {
|
|
||||||
activeColors[`text_${color}`] = ctx.editor.isActive("textStyle", { color });
|
|
||||||
});
|
|
||||||
HIGHLIGHT_COLORS.forEach(({ color }) => {
|
|
||||||
activeColors[`highlight_${color}`] = ctx.editor.isActive("highlight", { color });
|
|
||||||
});
|
|
||||||
|
|
||||||
return activeColors;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!editor || !editorState) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const activeColorItem = TEXT_COLORS.find(({ color }) =>
|
const activeColorItem = TEXT_COLORS.find(({ color }) =>
|
||||||
editorState[`text_${color}`]
|
editor.isActive("textStyle", { color }),
|
||||||
);
|
);
|
||||||
|
|
||||||
const activeHighlightItem = HIGHLIGHT_COLORS.find(({ color }) =>
|
const activeHighlightItem = HIGHLIGHT_COLORS.find(({ color }) =>
|
||||||
editorState[`highlight_${color}`]
|
editor.isActive("highlight", { color }),
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -176,7 +151,7 @@ export const ColorSelector: FC<ColorSelectorProps> = ({
|
|||||||
justify="left"
|
justify="left"
|
||||||
fullWidth
|
fullWidth
|
||||||
rightSection={
|
rightSection={
|
||||||
editorState[`text_${color}`] && (
|
editor.isActive("textStyle", { color }) && (
|
||||||
<IconCheck style={{ width: rem(16) }} />
|
<IconCheck style={{ width: rem(16) }} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ import {
|
|||||||
IconTypography,
|
IconTypography,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { Popover, Button, ScrollArea } from "@mantine/core";
|
import { Popover, Button, ScrollArea } from "@mantine/core";
|
||||||
import type { Editor } from "@tiptap/react";
|
import { useEditor } from "@tiptap/react";
|
||||||
import { useEditorState } from "@tiptap/react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
interface NodeSelectorProps {
|
interface NodeSelectorProps {
|
||||||
editor: Editor | null;
|
editor: ReturnType<typeof useEditor>;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
@@ -37,27 +36,6 @@ export const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
isParagraph: ctx.editor.isActive("paragraph"),
|
|
||||||
isBulletList: ctx.editor.isActive("bulletList"),
|
|
||||||
isOrderedList: ctx.editor.isActive("orderedList"),
|
|
||||||
isHeading1: ctx.editor.isActive("heading", { level: 1 }),
|
|
||||||
isHeading2: ctx.editor.isActive("heading", { level: 2 }),
|
|
||||||
isHeading3: ctx.editor.isActive("heading", { level: 3 }),
|
|
||||||
isTaskItem: ctx.editor.isActive("taskItem"),
|
|
||||||
isBlockquote: ctx.editor.isActive("blockquote"),
|
|
||||||
isCodeBlock: ctx.editor.isActive("codeBlock"),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const items: BubbleMenuItem[] = [
|
const items: BubbleMenuItem[] = [
|
||||||
{
|
{
|
||||||
name: "Text",
|
name: "Text",
|
||||||
@@ -65,45 +43,45 @@ export const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
command: () =>
|
command: () =>
|
||||||
editor.chain().focus().toggleNode("paragraph", "paragraph").run(),
|
editor.chain().focus().toggleNode("paragraph", "paragraph").run(),
|
||||||
isActive: () =>
|
isActive: () =>
|
||||||
editorState?.isParagraph &&
|
editor.isActive("paragraph") &&
|
||||||
!editorState?.isBulletList &&
|
!editor.isActive("bulletList") &&
|
||||||
!editorState?.isOrderedList,
|
!editor.isActive("orderedList"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Heading 1",
|
name: "Heading 1",
|
||||||
icon: IconH1,
|
icon: IconH1,
|
||||||
command: () => editor.chain().focus().toggleHeading({ level: 1 }).run(),
|
command: () => editor.chain().focus().toggleHeading({ level: 1 }).run(),
|
||||||
isActive: () => editorState?.isHeading1,
|
isActive: () => editor.isActive("heading", { level: 1 }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Heading 2",
|
name: "Heading 2",
|
||||||
icon: IconH2,
|
icon: IconH2,
|
||||||
command: () => editor.chain().focus().toggleHeading({ level: 2 }).run(),
|
command: () => editor.chain().focus().toggleHeading({ level: 2 }).run(),
|
||||||
isActive: () => editorState?.isHeading2,
|
isActive: () => editor.isActive("heading", { level: 2 }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Heading 3",
|
name: "Heading 3",
|
||||||
icon: IconH3,
|
icon: IconH3,
|
||||||
command: () => editor.chain().focus().toggleHeading({ level: 3 }).run(),
|
command: () => editor.chain().focus().toggleHeading({ level: 3 }).run(),
|
||||||
isActive: () => editorState?.isHeading3,
|
isActive: () => editor.isActive("heading", { level: 3 }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "To-do List",
|
name: "To-do List",
|
||||||
icon: IconCheckbox,
|
icon: IconCheckbox,
|
||||||
command: () => editor.chain().focus().toggleTaskList().run(),
|
command: () => editor.chain().focus().toggleTaskList().run(),
|
||||||
isActive: () => editorState?.isTaskItem,
|
isActive: () => editor.isActive("taskItem"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bullet List",
|
name: "Bullet List",
|
||||||
icon: IconList,
|
icon: IconList,
|
||||||
command: () => editor.chain().focus().toggleBulletList().run(),
|
command: () => editor.chain().focus().toggleBulletList().run(),
|
||||||
isActive: () => editorState?.isBulletList,
|
isActive: () => editor.isActive("bulletList"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Numbered List",
|
name: "Numbered List",
|
||||||
icon: IconListNumbers,
|
icon: IconListNumbers,
|
||||||
command: () => editor.chain().focus().toggleOrderedList().run(),
|
command: () => editor.chain().focus().toggleOrderedList().run(),
|
||||||
isActive: () => editorState?.isOrderedList,
|
isActive: () => editor.isActive("orderedList"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Blockquote",
|
name: "Blockquote",
|
||||||
@@ -115,13 +93,13 @@ export const NodeSelector: FC<NodeSelectorProps> = ({
|
|||||||
.toggleNode("paragraph", "paragraph")
|
.toggleNode("paragraph", "paragraph")
|
||||||
.toggleBlockquote()
|
.toggleBlockquote()
|
||||||
.run(),
|
.run(),
|
||||||
isActive: () => editorState?.isBlockquote,
|
isActive: () => editor.isActive("blockquote"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Code",
|
name: "Code",
|
||||||
icon: IconCode,
|
icon: IconCode,
|
||||||
command: () => editor.chain().focus().toggleCodeBlock().run(),
|
command: () => editor.chain().focus().toggleCodeBlock().run(),
|
||||||
isActive: () => editorState?.isCodeBlock,
|
isActive: () => editor.isActive("codeBlock"),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
+10
-29
@@ -8,12 +8,11 @@ import {
|
|||||||
IconChevronDown,
|
IconChevronDown,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { Popover, Button, ScrollArea, rem } from "@mantine/core";
|
import { Popover, Button, ScrollArea, rem } from "@mantine/core";
|
||||||
import type { Editor } from "@tiptap/react";
|
import { useEditor } from "@tiptap/react";
|
||||||
import { useEditorState } from "@tiptap/react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
interface TextAlignmentProps {
|
interface TextAlignmentProps {
|
||||||
editor: Editor | null;
|
editor: ReturnType<typeof useEditor>;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
@@ -32,54 +31,36 @@ export const TextAlignmentSelector: FC<TextAlignmentProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
isAlignLeft: ctx.editor.isActive({ textAlign: "left" }),
|
|
||||||
isAlignCenter: ctx.editor.isActive({ textAlign: "center" }),
|
|
||||||
isAlignRight: ctx.editor.isActive({ textAlign: "right" }),
|
|
||||||
isAlignJustify: ctx.editor.isActive({ textAlign: "justify" }),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!editor || !editorState) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const items: BubbleMenuItem[] = [
|
const items: BubbleMenuItem[] = [
|
||||||
{
|
{
|
||||||
name: "Align left",
|
name: "Align left",
|
||||||
isActive: () => editorState?.isAlignLeft,
|
isActive: () => editor.isActive({ textAlign: "left" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("left").run(),
|
command: () => editor.chain().focus().setTextAlign("left").run(),
|
||||||
icon: IconAlignLeft,
|
icon: IconAlignLeft,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Align center",
|
name: "Align center",
|
||||||
isActive: () => editorState?.isAlignCenter,
|
isActive: () => editor.isActive({ textAlign: "center" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("center").run(),
|
command: () => editor.chain().focus().setTextAlign("center").run(),
|
||||||
icon: IconAlignCenter,
|
icon: IconAlignCenter,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Align right",
|
name: "Align right",
|
||||||
isActive: () => editorState?.isAlignRight,
|
isActive: () => editor.isActive({ textAlign: "right" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("right").run(),
|
command: () => editor.chain().focus().setTextAlign("right").run(),
|
||||||
icon: IconAlignRight,
|
icon: IconAlignRight,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Justify",
|
name: "Justify",
|
||||||
isActive: () => editorState?.isAlignJustify,
|
isActive: () => editor.isActive({ textAlign: "justify" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("justify").run(),
|
command: () => editor.chain().focus().setTextAlign("justify").run(),
|
||||||
icon: IconAlignJustified,
|
icon: IconAlignJustified,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const activeItem = items.filter((item) => item.isActive()).pop() ?? items[0];
|
const activeItem = items.filter((item) => item.isActive()).pop() ?? {
|
||||||
|
name: "Multiple",
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover opened={isOpen} withArrow>
|
<Popover opened={isOpen} withArrow>
|
||||||
@@ -92,7 +73,7 @@ export const TextAlignmentSelector: FC<TextAlignmentProps> = ({
|
|||||||
rightSection={<IconChevronDown size={16} />}
|
rightSection={<IconChevronDown size={16} />}
|
||||||
onClick={() => setIsOpen(!isOpen)}
|
onClick={() => setIsOpen(!isOpen)}
|
||||||
>
|
>
|
||||||
<activeItem.icon style={{ width: rem(16) }} stroke={2} />
|
<IconAlignLeft style={{ width: rem(16) }} stroke={2} />
|
||||||
</Button>
|
</Button>
|
||||||
</Popover.Target>
|
</Popover.Target>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
BubbleMenu as BaseBubbleMenu,
|
BubbleMenu as BaseBubbleMenu,
|
||||||
findParentNode,
|
findParentNode,
|
||||||
posToDOMRect,
|
posToDOMRect,
|
||||||
useEditorState,
|
|
||||||
} from "@tiptap/react";
|
} from "@tiptap/react";
|
||||||
import React, { useCallback } from "react";
|
import React, { useCallback } from "react";
|
||||||
import { Node as PMNode } from "prosemirror-model";
|
import { Node as PMNode } from "prosemirror-model";
|
||||||
@@ -10,7 +9,7 @@ import {
|
|||||||
EditorMenuProps,
|
EditorMenuProps,
|
||||||
ShouldShowProps,
|
ShouldShowProps,
|
||||||
} from "@/features/editor/components/table/types/types.ts";
|
} from "@/features/editor/components/table/types/types.ts";
|
||||||
import { ActionIcon, Tooltip } from "@mantine/core";
|
import { ActionIcon, Tooltip, Divider } from "@mantine/core";
|
||||||
import {
|
import {
|
||||||
IconAlertTriangleFilled,
|
IconAlertTriangleFilled,
|
||||||
IconCircleCheckFilled,
|
IconCircleCheckFilled,
|
||||||
@@ -36,23 +35,6 @@ export function CalloutMenu({ editor }: EditorMenuProps) {
|
|||||||
[editor],
|
[editor],
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
isCallout: ctx.editor.isActive("callout"),
|
|
||||||
isInfo: ctx.editor.isActive("callout", { type: "info" }),
|
|
||||||
isSuccess: ctx.editor.isActive("callout", { type: "success" }),
|
|
||||||
isWarning: ctx.editor.isActive("callout", { type: "warning" }),
|
|
||||||
isDanger: ctx.editor.isActive("callout", { type: "danger" }),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getReferenceClientRect = useCallback(() => {
|
const getReferenceClientRect = useCallback(() => {
|
||||||
const { selection } = editor.state;
|
const { selection } = editor.state;
|
||||||
const predicate = (node: PMNode) => node.type.name === "callout";
|
const predicate = (node: PMNode) => node.type.name === "callout";
|
||||||
@@ -110,7 +92,7 @@ export function CalloutMenu({ editor }: EditorMenuProps) {
|
|||||||
return (
|
return (
|
||||||
<BaseBubbleMenu
|
<BaseBubbleMenu
|
||||||
editor={editor}
|
editor={editor}
|
||||||
pluginKey={`callout-menu`}
|
pluginKey={`callout-menu}`}
|
||||||
updateDelay={0}
|
updateDelay={0}
|
||||||
tippyOptions={{
|
tippyOptions={{
|
||||||
getReferenceClientRect,
|
getReferenceClientRect,
|
||||||
@@ -129,7 +111,9 @@ export function CalloutMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={() => setCalloutType("info")}
|
onClick={() => setCalloutType("info")}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Info")}
|
aria-label={t("Info")}
|
||||||
variant={editorState?.isInfo ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("callout", { type: "info" }) ? "light" : "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconInfoCircleFilled size={18} />
|
<IconInfoCircleFilled size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -140,7 +124,11 @@ export function CalloutMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={() => setCalloutType("success")}
|
onClick={() => setCalloutType("success")}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Success")}
|
aria-label={t("Success")}
|
||||||
variant={editorState?.isSuccess ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("callout", { type: "success" })
|
||||||
|
? "light"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconCircleCheckFilled size={18} />
|
<IconCircleCheckFilled size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -151,7 +139,11 @@ export function CalloutMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={() => setCalloutType("warning")}
|
onClick={() => setCalloutType("warning")}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Warning")}
|
aria-label={t("Warning")}
|
||||||
variant={editorState?.isWarning ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("callout", { type: "warning" })
|
||||||
|
? "light"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconAlertTriangleFilled size={18} />
|
<IconAlertTriangleFilled size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -162,7 +154,11 @@ export function CalloutMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={() => setCalloutType("danger")}
|
onClick={() => setCalloutType("danger")}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Danger")}
|
aria-label={t("Danger")}
|
||||||
variant={editorState?.isDanger ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("callout", { type: "danger" })
|
||||||
|
? "light"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconCircleXFilled size={18} />
|
<IconCircleXFilled size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ import {
|
|||||||
BubbleMenu as BaseBubbleMenu,
|
BubbleMenu as BaseBubbleMenu,
|
||||||
findParentNode,
|
findParentNode,
|
||||||
posToDOMRect,
|
posToDOMRect,
|
||||||
useEditorState,
|
} from '@tiptap/react';
|
||||||
} from "@tiptap/react";
|
import { useCallback } from 'react';
|
||||||
import { useCallback } from "react";
|
import { sticky } from 'tippy.js';
|
||||||
import { sticky } from "tippy.js";
|
import { Node as PMNode } from 'prosemirror-model';
|
||||||
import { Node as PMNode } from "prosemirror-model";
|
|
||||||
import {
|
import {
|
||||||
EditorMenuProps,
|
EditorMenuProps,
|
||||||
ShouldShowProps,
|
ShouldShowProps,
|
||||||
} from "@/features/editor/components/table/types/types.ts";
|
} from '@/features/editor/components/table/types/types.ts';
|
||||||
import { NodeWidthResize } from "@/features/editor/components/common/node-width-resize.tsx";
|
import { NodeWidthResize } from '@/features/editor/components/common/node-width-resize.tsx';
|
||||||
|
|
||||||
export function DrawioMenu({ editor }: EditorMenuProps) {
|
export function DrawioMenu({ editor }: EditorMenuProps) {
|
||||||
const shouldShow = useCallback(
|
const shouldShow = useCallback(
|
||||||
@@ -20,29 +19,14 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return editor.isActive("drawio") && editor.getAttributes("drawio")?.src;
|
return editor.isActive('drawio') && editor.getAttributes('drawio')?.src;
|
||||||
},
|
},
|
||||||
[editor],
|
[editor]
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const drawioAttr = ctx.editor.getAttributes("drawio");
|
|
||||||
return {
|
|
||||||
isDrawio: ctx.editor.isActive("drawio"),
|
|
||||||
width: drawioAttr?.width ? parseInt(drawioAttr.width) : null,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getReferenceClientRect = useCallback(() => {
|
const getReferenceClientRect = useCallback(() => {
|
||||||
const { selection } = editor.state;
|
const { selection } = editor.state;
|
||||||
const predicate = (node: PMNode) => node.type.name === "drawio";
|
const predicate = (node: PMNode) => node.type.name === 'drawio';
|
||||||
const parent = findParentNode(predicate)(selection);
|
const parent = findParentNode(predicate)(selection);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
@@ -55,37 +39,40 @@ export function DrawioMenu({ editor }: EditorMenuProps) {
|
|||||||
|
|
||||||
const onWidthChange = useCallback(
|
const onWidthChange = useCallback(
|
||||||
(value: number) => {
|
(value: number) => {
|
||||||
editor.commands.updateAttributes("drawio", { width: `${value}%` });
|
editor.commands.updateAttributes('drawio', { width: `${value}%` });
|
||||||
},
|
},
|
||||||
[editor],
|
[editor]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseBubbleMenu
|
<BaseBubbleMenu
|
||||||
editor={editor}
|
editor={editor}
|
||||||
pluginKey={`drawio-menu`}
|
pluginKey={`drawio-menu}`}
|
||||||
updateDelay={0}
|
updateDelay={0}
|
||||||
tippyOptions={{
|
tippyOptions={{
|
||||||
getReferenceClientRect,
|
getReferenceClientRect,
|
||||||
offset: [0, 8],
|
offset: [0, 8],
|
||||||
zIndex: 99,
|
zIndex: 99,
|
||||||
popperOptions: {
|
popperOptions: {
|
||||||
modifiers: [{ name: "flip", enabled: false }],
|
modifiers: [{ name: 'flip', enabled: false }],
|
||||||
},
|
},
|
||||||
plugins: [sticky],
|
plugins: [sticky],
|
||||||
sticky: "popper",
|
sticky: 'popper',
|
||||||
}}
|
}}
|
||||||
shouldShow={shouldShow}
|
shouldShow={shouldShow}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: 'flex',
|
||||||
flexDirection: "column",
|
flexDirection: 'column',
|
||||||
alignItems: "center",
|
alignItems: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{editorState?.width && (
|
{editor.getAttributes('drawio')?.width && (
|
||||||
<NodeWidthResize onChange={onWidthChange} value={editorState.width} />
|
<NodeWidthResize
|
||||||
|
onChange={onWidthChange}
|
||||||
|
value={parseInt(editor.getAttributes('drawio').width)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</BaseBubbleMenu>
|
</BaseBubbleMenu>
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ import {
|
|||||||
BubbleMenu as BaseBubbleMenu,
|
BubbleMenu as BaseBubbleMenu,
|
||||||
findParentNode,
|
findParentNode,
|
||||||
posToDOMRect,
|
posToDOMRect,
|
||||||
useEditorState,
|
} from '@tiptap/react';
|
||||||
} from "@tiptap/react";
|
import { useCallback } from 'react';
|
||||||
import { useCallback } from "react";
|
import { sticky } from 'tippy.js';
|
||||||
import { sticky } from "tippy.js";
|
import { Node as PMNode } from 'prosemirror-model';
|
||||||
import { Node as PMNode } from "prosemirror-model";
|
|
||||||
import {
|
import {
|
||||||
EditorMenuProps,
|
EditorMenuProps,
|
||||||
ShouldShowProps,
|
ShouldShowProps,
|
||||||
} from "@/features/editor/components/table/types/types.ts";
|
} from '@/features/editor/components/table/types/types.ts';
|
||||||
import { NodeWidthResize } from "@/features/editor/components/common/node-width-resize.tsx";
|
import { NodeWidthResize } from '@/features/editor/components/common/node-width-resize.tsx';
|
||||||
|
|
||||||
export function ExcalidrawMenu({ editor }: EditorMenuProps) {
|
export function ExcalidrawMenu({ editor }: EditorMenuProps) {
|
||||||
const shouldShow = useCallback(
|
const shouldShow = useCallback(
|
||||||
@@ -20,31 +19,14 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return editor.isActive('excalidraw') && editor.getAttributes('excalidraw')?.src;
|
||||||
editor.isActive("excalidraw") && editor.getAttributes("excalidraw")?.src
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
[editor],
|
[editor]
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const excalidrawAttr = ctx.editor.getAttributes("excalidraw");
|
|
||||||
return {
|
|
||||||
isExcalidraw: ctx.editor.isActive("excalidraw"),
|
|
||||||
width: excalidrawAttr?.width ? parseInt(excalidrawAttr.width) : null,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getReferenceClientRect = useCallback(() => {
|
const getReferenceClientRect = useCallback(() => {
|
||||||
const { selection } = editor.state;
|
const { selection } = editor.state;
|
||||||
const predicate = (node: PMNode) => node.type.name === "excalidraw";
|
const predicate = (node: PMNode) => node.type.name === 'excalidraw';
|
||||||
const parent = findParentNode(predicate)(selection);
|
const parent = findParentNode(predicate)(selection);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
@@ -57,9 +39,9 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
|
|||||||
|
|
||||||
const onWidthChange = useCallback(
|
const onWidthChange = useCallback(
|
||||||
(value: number) => {
|
(value: number) => {
|
||||||
editor.commands.updateAttributes("excalidraw", { width: `${value}%` });
|
editor.commands.updateAttributes('excalidraw', { width: `${value}%` });
|
||||||
},
|
},
|
||||||
[editor],
|
[editor]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -72,22 +54,25 @@ export function ExcalidrawMenu({ editor }: EditorMenuProps) {
|
|||||||
offset: [0, 8],
|
offset: [0, 8],
|
||||||
zIndex: 99,
|
zIndex: 99,
|
||||||
popperOptions: {
|
popperOptions: {
|
||||||
modifiers: [{ name: "flip", enabled: false }],
|
modifiers: [{ name: 'flip', enabled: false }],
|
||||||
},
|
},
|
||||||
plugins: [sticky],
|
plugins: [sticky],
|
||||||
sticky: "popper",
|
sticky: 'popper',
|
||||||
}}
|
}}
|
||||||
shouldShow={shouldShow}
|
shouldShow={shouldShow}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: 'flex',
|
||||||
flexDirection: "column",
|
flexDirection: 'column',
|
||||||
alignItems: "center",
|
alignItems: 'center',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{editorState?.width && (
|
{editor.getAttributes('excalidraw')?.width && (
|
||||||
<NodeWidthResize onChange={onWidthChange} value={editorState.width} />
|
<NodeWidthResize
|
||||||
|
onChange={onWidthChange}
|
||||||
|
value={parseInt(editor.getAttributes('excalidraw').width)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</BaseBubbleMenu>
|
</BaseBubbleMenu>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
BubbleMenu as BaseBubbleMenu,
|
BubbleMenu as BaseBubbleMenu,
|
||||||
findParentNode,
|
findParentNode,
|
||||||
posToDOMRect,
|
posToDOMRect,
|
||||||
useEditorState,
|
|
||||||
} from "@tiptap/react";
|
} from "@tiptap/react";
|
||||||
import React, { useCallback } from "react";
|
import React, { useCallback } from "react";
|
||||||
import { sticky } from "tippy.js";
|
import { sticky } from "tippy.js";
|
||||||
@@ -33,25 +32,6 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
[editor],
|
[editor],
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const imageAttrs = ctx.editor.getAttributes("image");
|
|
||||||
|
|
||||||
return {
|
|
||||||
isImage: ctx.editor.isActive("image"),
|
|
||||||
isAlignLeft: ctx.editor.isActive("image", { align: "left" }),
|
|
||||||
isAlignCenter: ctx.editor.isActive("image", { align: "center" }),
|
|
||||||
isAlignRight: ctx.editor.isActive("image", { align: "right" }),
|
|
||||||
width: imageAttrs?.width ? parseInt(imageAttrs.width) : null,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getReferenceClientRect = useCallback(() => {
|
const getReferenceClientRect = useCallback(() => {
|
||||||
const { selection } = editor.state;
|
const { selection } = editor.state;
|
||||||
const predicate = (node: PMNode) => node.type.name === "image";
|
const predicate = (node: PMNode) => node.type.name === "image";
|
||||||
@@ -103,7 +83,7 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
return (
|
return (
|
||||||
<BaseBubbleMenu
|
<BaseBubbleMenu
|
||||||
editor={editor}
|
editor={editor}
|
||||||
pluginKey={`image-menu`}
|
pluginKey={`image-menu}`}
|
||||||
updateDelay={0}
|
updateDelay={0}
|
||||||
tippyOptions={{
|
tippyOptions={{
|
||||||
getReferenceClientRect,
|
getReferenceClientRect,
|
||||||
@@ -123,7 +103,9 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={alignImageLeft}
|
onClick={alignImageLeft}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Align left")}
|
aria-label={t("Align left")}
|
||||||
variant={editorState?.isAlignLeft ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("image", { align: "left" }) ? "light" : "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconLayoutAlignLeft size={18} />
|
<IconLayoutAlignLeft size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -134,7 +116,11 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={alignImageCenter}
|
onClick={alignImageCenter}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Align center")}
|
aria-label={t("Align center")}
|
||||||
variant={editorState?.isAlignCenter ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("image", { align: "center" })
|
||||||
|
? "light"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconLayoutAlignCenter size={18} />
|
<IconLayoutAlignCenter size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -145,15 +131,20 @@ export function ImageMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={alignImageRight}
|
onClick={alignImageRight}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Align right")}
|
aria-label={t("Align right")}
|
||||||
variant={editorState?.isAlignRight ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("image", { align: "right" }) ? "light" : "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconLayoutAlignRight size={18} />
|
<IconLayoutAlignRight size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</ActionIcon.Group>
|
</ActionIcon.Group>
|
||||||
|
|
||||||
{editorState?.width && (
|
{editor.getAttributes("image")?.width && (
|
||||||
<NodeWidthResize onChange={onWidthChange} value={editorState.width} />
|
<NodeWidthResize
|
||||||
|
onChange={onWidthChange}
|
||||||
|
value={parseInt(editor.getAttributes("image").width)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</BaseBubbleMenu>
|
</BaseBubbleMenu>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { BubbleMenu as BaseBubbleMenu, useEditorState } from "@tiptap/react";
|
import { BubbleMenu as BaseBubbleMenu } from "@tiptap/react";
|
||||||
import React, { useCallback, useState } from "react";
|
import React, { useCallback, useState } from "react";
|
||||||
import { EditorMenuProps } from "@/features/editor/components/table/types/types.ts";
|
import { EditorMenuProps } from "@/features/editor/components/table/types/types.ts";
|
||||||
import { LinkEditorPanel } from "@/features/editor/components/link/link-editor-panel.tsx";
|
import { LinkEditorPanel } from "@/features/editor/components/link/link-editor-panel.tsx";
|
||||||
@@ -12,18 +12,7 @@ export function LinkMenu({ editor, appendTo }: EditorMenuProps) {
|
|||||||
return editor.isActive("link");
|
return editor.isActive("link");
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
const { href: link } = editor.getAttributes("link");
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const link = ctx.editor.getAttributes("link");
|
|
||||||
return {
|
|
||||||
href: link.href,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleEdit = useCallback(() => {
|
const handleEdit = useCallback(() => {
|
||||||
setShowEdit(true);
|
setShowEdit(true);
|
||||||
@@ -81,14 +70,11 @@ export function LinkMenu({ editor, appendTo }: EditorMenuProps) {
|
|||||||
padding="xs"
|
padding="xs"
|
||||||
bg="var(--mantine-color-body)"
|
bg="var(--mantine-color-body)"
|
||||||
>
|
>
|
||||||
<LinkEditorPanel
|
<LinkEditorPanel initialUrl={link} onSetLink={onSetLink} />
|
||||||
initialUrl={editorState?.href}
|
|
||||||
onSetLink={onSetLink}
|
|
||||||
/>
|
|
||||||
</Card>
|
</Card>
|
||||||
) : (
|
) : (
|
||||||
<LinkPreviewPanel
|
<LinkPreviewPanel
|
||||||
url={editorState?.href}
|
url={link}
|
||||||
onClear={onUnsetLink}
|
onClear={onUnsetLink}
|
||||||
onEdit={handleEdit}
|
onEdit={handleEdit}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import {
|
|||||||
IconCalendar,
|
IconCalendar,
|
||||||
IconAppWindow,
|
IconAppWindow,
|
||||||
IconSitemap,
|
IconSitemap,
|
||||||
IconAlignLeft2,
|
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import {
|
import {
|
||||||
CommandProps,
|
CommandProps,
|
||||||
@@ -154,14 +153,6 @@ const CommandGroups: SlashMenuGroupedItemsType = {
|
|||||||
command: ({ editor, range }: CommandProps) =>
|
command: ({ editor, range }: CommandProps) =>
|
||||||
editor.chain().focus().deleteRange(range).setHorizontalRule().run(),
|
editor.chain().focus().deleteRange(range).setHorizontalRule().run(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: "Table of contents",
|
|
||||||
description: "Insert table of contents",
|
|
||||||
searchTerms: ["toc"],
|
|
||||||
icon: IconAlignLeft2,
|
|
||||||
command: ({ editor, range }: CommandProps) =>
|
|
||||||
editor.chain().focus().deleteRange(range).insertTableOfContents().run(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: "Image",
|
title: "Image",
|
||||||
description: "Upload any image from your device.",
|
description: "Upload any image from your device.",
|
||||||
|
|||||||
-69
@@ -1,69 +0,0 @@
|
|||||||
.container {
|
|
||||||
counter-reset: h1 h2 h3 h4;
|
|
||||||
border-left: 1px solid
|
|
||||||
light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4));
|
|
||||||
}
|
|
||||||
|
|
||||||
.emptyState {
|
|
||||||
color: light-dark(
|
|
||||||
var(--mantine-color-dark-3),
|
|
||||||
var(--mantine-color-dark-2)
|
|
||||||
) !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
text-decoration: none;
|
|
||||||
outline: none;
|
|
||||||
cursor: pointer;
|
|
||||||
display: block;
|
|
||||||
width: 100%;
|
|
||||||
text-align: start;
|
|
||||||
word-wrap: break-word;
|
|
||||||
background-color: transparent;
|
|
||||||
color: var(--mantine-color-text);
|
|
||||||
font-size: var(--mantine-font-size-sm);
|
|
||||||
line-height: var(--mantine-line-height-sm);
|
|
||||||
padding: 6px;
|
|
||||||
border: none;
|
|
||||||
border-bottom: none !important;
|
|
||||||
padding-left: calc(var(--level) * 1rem);
|
|
||||||
|
|
||||||
&[style*="--level: 1"] {
|
|
||||||
counter-increment: h1;
|
|
||||||
counter-reset: h2 h3 h4;
|
|
||||||
padding-left: 6px;
|
|
||||||
&::before {
|
|
||||||
content: counter(h1) ". ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&[style*="--level: 2"] {
|
|
||||||
counter-increment: h2;
|
|
||||||
counter-reset: h3 h4;
|
|
||||||
&::before {
|
|
||||||
content: counter(h2) ". ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&[style*="--level: 3"] {
|
|
||||||
counter-increment: h3;
|
|
||||||
counter-reset: h4;
|
|
||||||
&::before {
|
|
||||||
content: counter(h3) ". ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&[style*="--level: 4"] {
|
|
||||||
counter-increment: h4;
|
|
||||||
&::before {
|
|
||||||
content: counter(h4) ". ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@mixin hover {
|
|
||||||
background-color: light-dark(
|
|
||||||
var(--mantine-color-gray-2),
|
|
||||||
var(--mantine-color-dark-6)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
import { Editor as CoreEditor } from "@tiptap/core";
|
|
||||||
import { TableOfContentsStorage } from "@tiptap/extension-table-of-contents";
|
|
||||||
import { NodeViewWrapper, useEditorState } from "@tiptap/react";
|
|
||||||
import { memo } from "react";
|
|
||||||
import classes from "./table-of-contents-nodeview.module.css";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { TextSelection } from "@tiptap/pm/state";
|
|
||||||
|
|
||||||
export type TableOfContentsProps = {
|
|
||||||
editor: CoreEditor;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const TableOfContentsNodeview = memo(
|
|
||||||
({ editor }: TableOfContentsProps) => {
|
|
||||||
const content = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) =>
|
|
||||||
(ctx.editor.storage.tableOfContents as TableOfContentsStorage)?.content,
|
|
||||||
});
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const onTocItemClick = (e, id) => {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
if (editor) {
|
|
||||||
const element = editor.view.dom.querySelector(`[data-toc-id="${id}"`);
|
|
||||||
const pos = editor.view.posAtDOM(element, 0);
|
|
||||||
|
|
||||||
// set focus
|
|
||||||
const tr = editor.view.state.tr;
|
|
||||||
|
|
||||||
tr.setSelection(new TextSelection(tr.doc.resolve(pos)));
|
|
||||||
|
|
||||||
editor.view.dispatch(tr);
|
|
||||||
|
|
||||||
editor.view.focus();
|
|
||||||
|
|
||||||
if (history.pushState) {
|
|
||||||
history.pushState(null, null, `#${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.scrollTo({
|
|
||||||
top: element.getBoundingClientRect().top + window.scrollY,
|
|
||||||
behavior: "smooth",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<NodeViewWrapper>
|
|
||||||
<div contentEditable={false}>
|
|
||||||
{content.length > 0 ? (
|
|
||||||
<div className={classes.container}>
|
|
||||||
{content
|
|
||||||
.filter((item) => item.level <= 4)
|
|
||||||
.map((item) => (
|
|
||||||
<a
|
|
||||||
key={item.id}
|
|
||||||
href={`#${item.id}`}
|
|
||||||
style={{ "--level": item.level } as React.CSSProperties}
|
|
||||||
onClick={(e) => onTocItemClick(e, item.id)}
|
|
||||||
className={classes.link}
|
|
||||||
data-item-index={item.itemIndex}
|
|
||||||
draggable="false"
|
|
||||||
>
|
|
||||||
{item.textContent}
|
|
||||||
</a>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className={classes.emptyState}>
|
|
||||||
{t("No table of contents yet")}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</NodeViewWrapper>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
TableOfContentsNodeview.displayName = "TableOfContentsNodeview";
|
|
||||||
@@ -9,8 +9,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
UnstyledButton,
|
UnstyledButton,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import type { Editor } from "@tiptap/react";
|
import { useEditor } from "@tiptap/react";
|
||||||
import { useEditorState } from "@tiptap/react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export interface TableColorItem {
|
export interface TableColorItem {
|
||||||
@@ -19,7 +18,7 @@ export interface TableColorItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface TableBackgroundColorProps {
|
interface TableBackgroundColorProps {
|
||||||
editor: Editor | null;
|
editor: ReturnType<typeof useEditor>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TABLE_COLORS: TableColorItem[] = [
|
const TABLE_COLORS: TableColorItem[] = [
|
||||||
@@ -39,50 +38,37 @@ export const TableBackgroundColor: FC<TableBackgroundColorProps> = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [opened, setOpened] = React.useState(false);
|
const [opened, setOpened] = React.useState(false);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentColor = "";
|
|
||||||
if (ctx.editor.isActive("tableCell")) {
|
|
||||||
const attrs = ctx.editor.getAttributes("tableCell");
|
|
||||||
currentColor = attrs.backgroundColor || "";
|
|
||||||
} else if (ctx.editor.isActive("tableHeader")) {
|
|
||||||
const attrs = ctx.editor.getAttributes("tableHeader");
|
|
||||||
currentColor = attrs.backgroundColor || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
currentColor,
|
|
||||||
isTableCell: ctx.editor.isActive("tableCell"),
|
|
||||||
isTableHeader: ctx.editor.isActive("tableHeader"),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!editor || !editorState) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const setTableCellBackground = (color: string, colorName: string) => {
|
const setTableCellBackground = (color: string, colorName: string) => {
|
||||||
editor
|
editor
|
||||||
.chain()
|
.chain()
|
||||||
.focus()
|
.focus()
|
||||||
.updateAttributes("tableCell", {
|
.updateAttributes("tableCell", {
|
||||||
backgroundColor: color || null,
|
backgroundColor: color || null,
|
||||||
backgroundColorName: color ? colorName : null,
|
backgroundColorName: color ? colorName : null
|
||||||
})
|
})
|
||||||
.updateAttributes("tableHeader", {
|
.updateAttributes("tableHeader", {
|
||||||
backgroundColor: color || null,
|
backgroundColor: color || null,
|
||||||
backgroundColorName: color ? colorName : null,
|
backgroundColorName: color ? colorName : null
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
setOpened(false);
|
setOpened(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get current cell's background color
|
||||||
|
const getCurrentColor = () => {
|
||||||
|
if (editor.isActive("tableCell")) {
|
||||||
|
const attrs = editor.getAttributes("tableCell");
|
||||||
|
return attrs.backgroundColor || "";
|
||||||
|
}
|
||||||
|
if (editor.isActive("tableHeader")) {
|
||||||
|
const attrs = editor.getAttributes("tableHeader");
|
||||||
|
return attrs.backgroundColor || "";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentColor = getCurrentColor();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
width={200}
|
width={200}
|
||||||
@@ -137,7 +123,7 @@ export const TableBackgroundColor: FC<TableBackgroundColorProps> = ({
|
|||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{editorState.currentColor === item.color && (
|
{currentColor === item.color && (
|
||||||
<IconCheck
|
<IconCheck
|
||||||
size={18}
|
size={18}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ import {
|
|||||||
ActionIcon,
|
ActionIcon,
|
||||||
Button,
|
Button,
|
||||||
Popover,
|
Popover,
|
||||||
|
rem,
|
||||||
ScrollArea,
|
ScrollArea,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import type { Editor } from "@tiptap/react";
|
import { useEditor } from "@tiptap/react";
|
||||||
import { useEditorState } from "@tiptap/react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
interface TableTextAlignmentProps {
|
interface TableTextAlignmentProps {
|
||||||
editor: Editor | null;
|
editor: ReturnType<typeof useEditor>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AlignmentItem {
|
interface AlignmentItem {
|
||||||
@@ -32,44 +32,25 @@ export const TableTextAlignment: FC<TableTextAlignmentProps> = ({ editor }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [opened, setOpened] = React.useState(false);
|
const [opened, setOpened] = React.useState(false);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
isAlignLeft: ctx.editor.isActive({ textAlign: "left" }),
|
|
||||||
isAlignCenter: ctx.editor.isActive({ textAlign: "center" }),
|
|
||||||
isAlignRight: ctx.editor.isActive({ textAlign: "right" }),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!editor || !editorState) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const items: AlignmentItem[] = [
|
const items: AlignmentItem[] = [
|
||||||
{
|
{
|
||||||
name: "Align left",
|
name: "Align left",
|
||||||
value: "left",
|
value: "left",
|
||||||
isActive: () => editorState?.isAlignLeft,
|
isActive: () => editor.isActive({ textAlign: "left" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("left").run(),
|
command: () => editor.chain().focus().setTextAlign("left").run(),
|
||||||
icon: IconAlignLeft,
|
icon: IconAlignLeft,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Align center",
|
name: "Align center",
|
||||||
value: "center",
|
value: "center",
|
||||||
isActive: () => editorState?.isAlignCenter,
|
isActive: () => editor.isActive({ textAlign: "center" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("center").run(),
|
command: () => editor.chain().focus().setTextAlign("center").run(),
|
||||||
icon: IconAlignCenter,
|
icon: IconAlignCenter,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Align right",
|
name: "Align right",
|
||||||
value: "right",
|
value: "right",
|
||||||
isActive: () => editorState?.isAlignRight,
|
isActive: () => editor.isActive({ textAlign: "right" }),
|
||||||
command: () => editor.chain().focus().setTextAlign("right").run(),
|
command: () => editor.chain().focus().setTextAlign("right").run(),
|
||||||
icon: IconAlignRight,
|
icon: IconAlignRight,
|
||||||
},
|
},
|
||||||
@@ -83,7 +64,7 @@ export const TableTextAlignment: FC<TableTextAlignmentProps> = ({ editor }) => {
|
|||||||
onChange={setOpened}
|
onChange={setOpened}
|
||||||
position="bottom"
|
position="bottom"
|
||||||
withArrow
|
withArrow
|
||||||
transitionProps={{ transition: "pop" }}
|
transitionProps={{ transition: 'pop' }}
|
||||||
>
|
>
|
||||||
<Popover.Target>
|
<Popover.Target>
|
||||||
<Tooltip label={t("Text alignment")} withArrow>
|
<Tooltip label={t("Text alignment")} withArrow>
|
||||||
@@ -106,7 +87,9 @@ export const TableTextAlignment: FC<TableTextAlignmentProps> = ({ editor }) => {
|
|||||||
key={index}
|
key={index}
|
||||||
variant="default"
|
variant="default"
|
||||||
leftSection={<item.icon size={16} />}
|
leftSection={<item.icon size={16} />}
|
||||||
rightSection={item.isActive() && <IconCheck size={16} />}
|
rightSection={
|
||||||
|
item.isActive() && <IconCheck size={16} />
|
||||||
|
}
|
||||||
justify="left"
|
justify="left"
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -123,4 +106,4 @@ export const TableTextAlignment: FC<TableTextAlignmentProps> = ({ editor }) => {
|
|||||||
</Popover.Dropdown>
|
</Popover.Dropdown>
|
||||||
</Popover>
|
</Popover>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
BubbleMenu as BaseBubbleMenu,
|
BubbleMenu as BaseBubbleMenu,
|
||||||
findParentNode,
|
findParentNode,
|
||||||
posToDOMRect,
|
posToDOMRect,
|
||||||
useEditorState,
|
|
||||||
} from "@tiptap/react";
|
} from "@tiptap/react";
|
||||||
import React, { useCallback } from "react";
|
import React, { useCallback } from "react";
|
||||||
import { sticky } from "tippy.js";
|
import { sticky } from "tippy.js";
|
||||||
@@ -33,25 +32,6 @@ export function VideoMenu({ editor }: EditorMenuProps) {
|
|||||||
[editor],
|
[editor],
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorState = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
if (!ctx.editor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const videoAttrs = ctx.editor.getAttributes("video");
|
|
||||||
|
|
||||||
return {
|
|
||||||
isVideo: ctx.editor.isActive("video"),
|
|
||||||
isAlignLeft: ctx.editor.isActive("video", { align: "left" }),
|
|
||||||
isAlignCenter: ctx.editor.isActive("video", { align: "center" }),
|
|
||||||
isAlignRight: ctx.editor.isActive("video", { align: "right" }),
|
|
||||||
width: videoAttrs?.width ? parseInt(videoAttrs.width) : null,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getReferenceClientRect = useCallback(() => {
|
const getReferenceClientRect = useCallback(() => {
|
||||||
const { selection } = editor.state;
|
const { selection } = editor.state;
|
||||||
const predicate = (node: PMNode) => node.type.name === "video";
|
const predicate = (node: PMNode) => node.type.name === "video";
|
||||||
@@ -103,7 +83,7 @@ export function VideoMenu({ editor }: EditorMenuProps) {
|
|||||||
return (
|
return (
|
||||||
<BaseBubbleMenu
|
<BaseBubbleMenu
|
||||||
editor={editor}
|
editor={editor}
|
||||||
pluginKey={`video-menu`}
|
pluginKey={`video-menu}`}
|
||||||
updateDelay={0}
|
updateDelay={0}
|
||||||
tippyOptions={{
|
tippyOptions={{
|
||||||
getReferenceClientRect,
|
getReferenceClientRect,
|
||||||
@@ -123,7 +103,9 @@ export function VideoMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={alignVideoLeft}
|
onClick={alignVideoLeft}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Align left")}
|
aria-label={t("Align left")}
|
||||||
variant={editorState?.isAlignLeft ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("video", { align: "left" }) ? "light" : "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconLayoutAlignLeft size={18} />
|
<IconLayoutAlignLeft size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -134,7 +116,11 @@ export function VideoMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={alignVideoCenter}
|
onClick={alignVideoCenter}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Align center")}
|
aria-label={t("Align center")}
|
||||||
variant={editorState?.isAlignCenter ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("video", { align: "center" })
|
||||||
|
? "light"
|
||||||
|
: "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconLayoutAlignCenter size={18} />
|
<IconLayoutAlignCenter size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
@@ -145,15 +131,20 @@ export function VideoMenu({ editor }: EditorMenuProps) {
|
|||||||
onClick={alignVideoRight}
|
onClick={alignVideoRight}
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label={t("Align right")}
|
aria-label={t("Align right")}
|
||||||
variant={editorState?.isAlignRight ? "light" : "default"}
|
variant={
|
||||||
|
editor.isActive("video", { align: "right" }) ? "light" : "default"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<IconLayoutAlignRight size={18} />
|
<IconLayoutAlignRight size={18} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</ActionIcon.Group>
|
</ActionIcon.Group>
|
||||||
|
|
||||||
{editorState?.width && (
|
{editor.getAttributes("video")?.width && (
|
||||||
<NodeWidthResize onChange={onWidthChange} value={editorState.width} />
|
<NodeWidthResize
|
||||||
|
onChange={onWidthChange}
|
||||||
|
value={parseInt(editor.getAttributes("video").width)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</BaseBubbleMenu>
|
</BaseBubbleMenu>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { Typography } from "@tiptap/extension-typography";
|
|||||||
import { TextStyle } from "@tiptap/extension-text-style";
|
import { TextStyle } from "@tiptap/extension-text-style";
|
||||||
import { Color } from "@tiptap/extension-color";
|
import { Color } from "@tiptap/extension-color";
|
||||||
import SlashCommand from "@/features/editor/extensions/slash-command";
|
import SlashCommand from "@/features/editor/extensions/slash-command";
|
||||||
import { TableOfContents as TiptapTableOfContents } from "@tiptap/extension-table-of-contents";
|
|
||||||
import { Collaboration } from "@tiptap/extension-collaboration";
|
import { Collaboration } from "@tiptap/extension-collaboration";
|
||||||
import { CollaborationCursor } from "@tiptap/extension-collaboration-cursor";
|
import { CollaborationCursor } from "@tiptap/extension-collaboration-cursor";
|
||||||
import { HocuspocusProvider } from "@hocuspocus/provider";
|
import { HocuspocusProvider } from "@hocuspocus/provider";
|
||||||
@@ -41,8 +40,6 @@ import {
|
|||||||
Mention,
|
Mention,
|
||||||
Subpages,
|
Subpages,
|
||||||
TableDndExtension,
|
TableDndExtension,
|
||||||
TableOfContentsNode,
|
|
||||||
generateNodeId,
|
|
||||||
} from "@docmost/editor-ext";
|
} from "@docmost/editor-ext";
|
||||||
import {
|
import {
|
||||||
randomElement,
|
randomElement,
|
||||||
@@ -81,7 +78,6 @@ import { MarkdownClipboard } from "@/features/editor/extensions/markdown-clipboa
|
|||||||
import EmojiCommand from "./emoji-command";
|
import EmojiCommand from "./emoji-command";
|
||||||
import { CharacterCount } from "@tiptap/extension-character-count";
|
import { CharacterCount } from "@tiptap/extension-character-count";
|
||||||
import { countWords } from "alfaaz";
|
import { countWords } from "alfaaz";
|
||||||
import { TableOfContentsNodeview } from "@/features/editor/components/table-of-contents/table-of-contents-nodeview.tsx";
|
|
||||||
|
|
||||||
const lowlight = createLowlight(common);
|
const lowlight = createLowlight(common);
|
||||||
lowlight.register("mermaid", plaintext);
|
lowlight.register("mermaid", plaintext);
|
||||||
@@ -232,25 +228,19 @@ export const mainExtensions = [
|
|||||||
SearchAndReplace.extend({
|
SearchAndReplace.extend({
|
||||||
addKeyboardShortcuts() {
|
addKeyboardShortcuts() {
|
||||||
return {
|
return {
|
||||||
"Mod-f": () => {
|
'Mod-f': () => {
|
||||||
const event = new CustomEvent("openFindDialogFromEditor", {});
|
const event = new CustomEvent("openFindDialogFromEditor", {});
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Escape: () => {
|
'Escape': () => {
|
||||||
const event = new CustomEvent("closeFindDialogFromEditor", {});
|
const event = new CustomEvent("closeFindDialogFromEditor", {});
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
}).configure(),
|
}).configure(),
|
||||||
TiptapTableOfContents.configure({
|
|
||||||
getId: () => generateNodeId(),
|
|
||||||
}),
|
|
||||||
TableOfContentsNode.configure({
|
|
||||||
view: TableOfContentsNodeview,
|
|
||||||
}),
|
|
||||||
] as any;
|
] as any;
|
||||||
|
|
||||||
type CollabExtensions = (provider: HocuspocusProvider, user: IUser) => any[];
|
type CollabExtensions = (provider: HocuspocusProvider, user: IUser) => any[];
|
||||||
|
|||||||
@@ -7,12 +7,7 @@ import {
|
|||||||
onAuthenticationFailedParameters,
|
onAuthenticationFailedParameters,
|
||||||
WebSocketStatus,
|
WebSocketStatus,
|
||||||
} from "@hocuspocus/provider";
|
} from "@hocuspocus/provider";
|
||||||
import {
|
import { EditorContent, EditorProvider, useEditor } from "@tiptap/react";
|
||||||
EditorContent,
|
|
||||||
EditorProvider,
|
|
||||||
useEditor,
|
|
||||||
useEditorState,
|
|
||||||
} from "@tiptap/react";
|
|
||||||
import {
|
import {
|
||||||
collabExtensions,
|
collabExtensions,
|
||||||
mainExtensions,
|
mainExtensions,
|
||||||
@@ -55,7 +50,7 @@ import { extractPageSlugId } from "@/lib";
|
|||||||
import { FIVE_MINUTES } from "@/lib/constants.ts";
|
import { FIVE_MINUTES } from "@/lib/constants.ts";
|
||||||
import { PageEditMode } from "@/features/user/types/user.types.ts";
|
import { PageEditMode } from "@/features/user/types/user.types.ts";
|
||||||
import { jwtDecode } from "jwt-decode";
|
import { jwtDecode } from "jwt-decode";
|
||||||
import { searchSpotlight } from "@/features/search/constants.ts";
|
import { searchSpotlight } from '@/features/search/constants.ts';
|
||||||
|
|
||||||
interface PageEditorProps {
|
interface PageEditorProps {
|
||||||
pageId: string;
|
pageId: string;
|
||||||
@@ -82,7 +77,7 @@ export default function PageEditor({
|
|||||||
const [isLocalSynced, setLocalSynced] = useState(false);
|
const [isLocalSynced, setLocalSynced] = useState(false);
|
||||||
const [isRemoteSynced, setRemoteSynced] = useState(false);
|
const [isRemoteSynced, setRemoteSynced] = useState(false);
|
||||||
const [yjsConnectionStatus, setYjsConnectionStatus] = useAtom(
|
const [yjsConnectionStatus, setYjsConnectionStatus] = useAtom(
|
||||||
yjsConnectionStatusAtom,
|
yjsConnectionStatusAtom
|
||||||
);
|
);
|
||||||
const menuContainerRef = useRef(null);
|
const menuContainerRef = useRef(null);
|
||||||
const documentName = `page.${pageId}`;
|
const documentName = `page.${pageId}`;
|
||||||
@@ -218,17 +213,17 @@ export default function PageEditor({
|
|||||||
extensions,
|
extensions,
|
||||||
editable,
|
editable,
|
||||||
immediatelyRender: true,
|
immediatelyRender: true,
|
||||||
shouldRerenderOnTransaction: false,
|
shouldRerenderOnTransaction: true,
|
||||||
editorProps: {
|
editorProps: {
|
||||||
scrollThreshold: 80,
|
scrollThreshold: 80,
|
||||||
scrollMargin: 80,
|
scrollMargin: 80,
|
||||||
handleDOMEvents: {
|
handleDOMEvents: {
|
||||||
keydown: (_view, event) => {
|
keydown: (_view, event) => {
|
||||||
if ((event.ctrlKey || event.metaKey) && event.code === "KeyS") {
|
if ((event.ctrlKey || event.metaKey) && event.code === 'KeyS') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((event.ctrlKey || event.metaKey) && event.code === "KeyK") {
|
if ((event.ctrlKey || event.metaKey) && event.code === 'KeyK') {
|
||||||
searchSpotlight.open();
|
searchSpotlight.open();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -273,16 +268,9 @@ export default function PageEditor({
|
|||||||
debouncedUpdateContent(editorJson);
|
debouncedUpdateContent(editorJson);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[pageId, editable, remoteProvider],
|
[pageId, editable, remoteProvider]
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorIsEditable = useEditorState({
|
|
||||||
editor,
|
|
||||||
selector: (ctx) => {
|
|
||||||
return ctx.editor?.isEditable ?? false;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const debouncedUpdateContent = useDebouncedCallback((newContent: any) => {
|
const debouncedUpdateContent = useDebouncedCallback((newContent: any) => {
|
||||||
const pageData = queryClient.getQueryData<IPage>(["pages", slugId]);
|
const pageData = queryClient.getQueryData<IPage>(["pages", slugId]);
|
||||||
|
|
||||||
@@ -318,7 +306,7 @@ export default function PageEditor({
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener(
|
document.removeEventListener(
|
||||||
"ACTIVE_COMMENT_EVENT",
|
"ACTIVE_COMMENT_EVENT",
|
||||||
handleActiveCommentEvent,
|
handleActiveCommentEvent
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
@@ -401,7 +389,7 @@ export default function PageEditor({
|
|||||||
<SearchAndReplaceDialog editor={editor} editable={editable} />
|
<SearchAndReplaceDialog editor={editor} editable={editable} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{editor && editorIsEditable && (
|
{editor && editor.isEditable && (
|
||||||
<div>
|
<div>
|
||||||
<EditorBubbleMenu editor={editor} />
|
<EditorBubbleMenu editor={editor} />
|
||||||
<TableMenu editor={editor} />
|
<TableMenu editor={editor} />
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { Group, Box, Button, TextInput, Stack, Textarea } from "@mantine/core";
|
import { Group, Box, Button, TextInput, Stack, Textarea } from "@mantine/core";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useCreateGroupMutation } from "@/features/group/queries/group-query.ts";
|
import { useCreateGroupMutation } from "@/features/group/queries/group-query.ts";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm, zodResolver } from "@mantine/form";
|
||||||
import * as z from "zod";
|
import * as z from "zod";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { MultiUserSelect } from "@/features/group/components/multi-user-select.tsx";
|
import { MultiUserSelect } from "@/features/group/components/multi-user-select.tsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { zodResolver } from 'mantine-form-zod-resolver';
|
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
name: z.string().trim().min(2).max(50),
|
name: z.string().trim().min(2).max(50),
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import {
|
|||||||
useGroupQuery,
|
useGroupQuery,
|
||||||
useUpdateGroupMutation,
|
useUpdateGroupMutation,
|
||||||
} from "@/features/group/queries/group-query.ts";
|
} from "@/features/group/queries/group-query.ts";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm, zodResolver } from "@mantine/form";
|
||||||
import * as z from "zod";
|
import * as z from "zod";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { zodResolver } from "mantine-form-zod-resolver";
|
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
name: z.string().min(2).max(50),
|
name: z.string().min(2).max(50),
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import { IUser } from "@/features/user/types/user.types.ts";
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { validate as isValidUuid } from "uuid";
|
import { validate as isValidUuid } from "uuid";
|
||||||
import { queryClient } from "@/main.tsx";
|
import { queryClient } from "@/main.tsx";
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
export function useGetGroupsQuery(
|
export function useGetGroupsQuery(
|
||||||
params?: QueryParams,
|
params?: QueryParams,
|
||||||
@@ -74,12 +73,11 @@ export function useCreateGroupMutation() {
|
|||||||
|
|
||||||
export function useUpdateGroupMutation() {
|
export function useUpdateGroupMutation() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation<IGroup, Error, Partial<IGroup>>({
|
return useMutation<IGroup, Error, Partial<IGroup>>({
|
||||||
mutationFn: (data) => updateGroup(data),
|
mutationFn: (data) => updateGroup(data),
|
||||||
onSuccess: (data, variables) => {
|
onSuccess: (data, variables) => {
|
||||||
notifications.show({ message: t("Group updated successfully") });
|
notifications.show({ message: "Group updated successfully" });
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["group", variables.groupId],
|
queryKey: ["group", variables.groupId],
|
||||||
});
|
});
|
||||||
@@ -93,12 +91,11 @@ export function useUpdateGroupMutation() {
|
|||||||
|
|
||||||
export function useDeleteGroupMutation() {
|
export function useDeleteGroupMutation() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (groupId: string) => deleteGroup({ groupId }),
|
mutationFn: (groupId: string) => deleteGroup({ groupId }),
|
||||||
onSuccess: (data, variables) => {
|
onSuccess: (data, variables) => {
|
||||||
notifications.show({ message: t("Group deleted successfully") });
|
notifications.show({ message: "Group deleted successfully" });
|
||||||
queryClient.refetchQueries({ queryKey: ["groups"] });
|
queryClient.refetchQueries({ queryKey: ["groups"] });
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
@@ -122,12 +119,11 @@ export function useGroupMembersQuery(
|
|||||||
|
|
||||||
export function useAddGroupMemberMutation() {
|
export function useAddGroupMemberMutation() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation<void, Error, { groupId: string; userIds: string[] }>({
|
return useMutation<void, Error, { groupId: string; userIds: string[] }>({
|
||||||
mutationFn: (data) => addGroupMember(data),
|
mutationFn: (data) => addGroupMember(data),
|
||||||
onSuccess: (data, variables) => {
|
onSuccess: (data, variables) => {
|
||||||
notifications.show({ message: t("Added successfully") });
|
notifications.show({ message: "Added successfully" });
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["groupMembers", variables.groupId],
|
queryKey: ["groupMembers", variables.groupId],
|
||||||
});
|
});
|
||||||
@@ -143,7 +139,6 @@ export function useAddGroupMemberMutation() {
|
|||||||
|
|
||||||
export function useRemoveGroupMemberMutation() {
|
export function useRemoveGroupMemberMutation() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
void,
|
void,
|
||||||
@@ -155,7 +150,7 @@ export function useRemoveGroupMemberMutation() {
|
|||||||
>({
|
>({
|
||||||
mutationFn: (data) => removeGroupMember(data),
|
mutationFn: (data) => removeGroupMember(data),
|
||||||
onSuccess: (data, variables) => {
|
onSuccess: (data, variables) => {
|
||||||
notifications.show({ message: t("Removed successfully") });
|
notifications.show({ message: "Removed successfully" });
|
||||||
queryClient.invalidateQueries({
|
queryClient.invalidateQueries({
|
||||||
queryKey: ["groupMembers", variables.groupId],
|
queryKey: ["groupMembers", variables.groupId],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { SearchSpotlightFilters } from "./search-spotlight-filters.tsx";
|
|||||||
import { useUnifiedSearch } from "../hooks/use-unified-search.ts";
|
import { useUnifiedSearch } from "../hooks/use-unified-search.ts";
|
||||||
import { SearchResultItem } from "./search-result-item.tsx";
|
import { SearchResultItem } from "./search-result-item.tsx";
|
||||||
import { useLicense } from "@/ee/hooks/use-license.tsx";
|
import { useLicense } from "@/ee/hooks/use-license.tsx";
|
||||||
import { isCloud } from "@/lib/config.ts";
|
|
||||||
|
|
||||||
interface SearchSpotlightProps {
|
interface SearchSpotlightProps {
|
||||||
spaceId?: string;
|
spaceId?: string;
|
||||||
@@ -44,7 +43,7 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
|
|
||||||
// Determine result type for rendering
|
// Determine result type for rendering
|
||||||
const isAttachmentSearch =
|
const isAttachmentSearch =
|
||||||
filters.contentType === "attachment" && (hasLicenseKey || isCloud());
|
filters.contentType === "attachment" && hasLicenseKey;
|
||||||
|
|
||||||
const resultItems = (searchResults || []).map((result) => (
|
const resultItems = (searchResults || []).map((result) => (
|
||||||
<SearchResultItem
|
<SearchResultItem
|
||||||
|
|||||||
@@ -8,11 +8,20 @@ import { useTranslation } from "react-i18next";
|
|||||||
import Paginate from "@/components/common/paginate.tsx";
|
import Paginate from "@/components/common/paginate.tsx";
|
||||||
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
||||||
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
import { userAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import { UserRole } from "@/lib/types.ts";
|
||||||
|
import { useIsEEOnly } from "@/hooks/use-is-cloud-ee.tsx";
|
||||||
|
|
||||||
export default function SpaceList() {
|
export default function SpaceList() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const { data, isLoading } = useGetSpacesQuery({ page });
|
const [user] = useAtom(userAtom);
|
||||||
|
const isEEOnly = useIsEEOnly();
|
||||||
|
const { data, isLoading } = useGetSpacesQuery({
|
||||||
|
page,
|
||||||
|
...(isEEOnly && user.role === UserRole.OWNER && { includeAllSpaces: true }),
|
||||||
|
});
|
||||||
const [opened, { open, close }] = useDisclosure(false);
|
const [opened, { open, close }] = useDisclosure(false);
|
||||||
const [selectedSpaceId, setSelectedSpaceId] = useState<string>(null);
|
const [selectedSpaceId, setSelectedSpaceId] = useState<string>(null);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import { isCloud } from "@/lib/config";
|
import { isCloud } from "@/lib/config";
|
||||||
import { useLicense } from "@/ee/hooks/use-license";
|
import { useLicense } from "@/ee/hooks/use-license";
|
||||||
|
import { useAtom } from "jotai/index";
|
||||||
|
import { currentUserAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import usePlan from "@/ee/hooks/use-plan";
|
||||||
|
|
||||||
export const useIsCloudEE = () => {
|
export const useIsCloudEE = () => {
|
||||||
const { hasLicenseKey } = useLicense();
|
const { hasLicenseKey } = useLicense();
|
||||||
return isCloud() || !!hasLicenseKey;
|
return isCloud() || !!hasLicenseKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useIsEEOnly = () => {
|
||||||
|
const { hasLicenseKey } = useLicense();
|
||||||
|
const { isBusiness } = usePlan();
|
||||||
|
return (isCloud() && isBusiness) || !!hasLicenseKey;
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ export interface QueryParams {
|
|||||||
query?: string;
|
query?: string;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
adminView?: boolean;
|
includeAllSpaces?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum UserRole {
|
export enum UserRole {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import "@mantine/core/styles.css";
|
import "@mantine/core/styles.css";
|
||||||
import "@mantine/spotlight/styles.css";
|
import "@mantine/spotlight/styles.css";
|
||||||
import "@mantine/notifications/styles.css";
|
import "@mantine/notifications/styles.css";
|
||||||
import '@mantine/dates/styles.css';
|
|
||||||
|
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import App from "./App.tsx";
|
import App from "./App.tsx";
|
||||||
import { mantineCssResolver, theme } from "@/theme";
|
import { mantineCssResolver, theme } from "@/theme";
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
"@fastify/cookie": "^11.0.2",
|
"@fastify/cookie": "^11.0.2",
|
||||||
"@fastify/multipart": "^9.0.3",
|
"@fastify/multipart": "^9.0.3",
|
||||||
"@fastify/static": "^8.2.0",
|
"@fastify/static": "^8.2.0",
|
||||||
"@nestjs-labs/nestjs-ioredis": "^11.0.4",
|
|
||||||
"@nestjs/bullmq": "^11.0.2",
|
"@nestjs/bullmq": "^11.0.2",
|
||||||
"@nestjs/common": "^11.1.3",
|
"@nestjs/common": "^11.1.3",
|
||||||
"@nestjs/config": "^4.0.2",
|
"@nestjs/config": "^4.0.2",
|
||||||
@@ -56,15 +55,14 @@
|
|||||||
"@react-email/render": "1.0.2",
|
"@react-email/render": "1.0.2",
|
||||||
"@socket.io/redis-adapter": "^8.3.0",
|
"@socket.io/redis-adapter": "^8.3.0",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"bullmq": "^5.61.0",
|
"bullmq": "^5.53.2",
|
||||||
"cache-manager": "^6.4.3",
|
"cache-manager": "^6.4.3",
|
||||||
"cheerio": "^1.1.0",
|
"cheerio": "^1.1.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.1",
|
"class-validator": "^0.14.1",
|
||||||
"cookie": "^1.0.2",
|
"cookie": "^1.0.2",
|
||||||
"fs-extra": "^11.3.0",
|
"fs-extra": "^11.3.0",
|
||||||
"happy-dom": "^18.0.1",
|
"happy-dom": "^15.11.6",
|
||||||
"ioredis": "^5.4.1",
|
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"kysely": "^0.28.2",
|
"kysely": "^0.28.2",
|
||||||
"kysely-migration-cli": "^0.4.2",
|
"kysely-migration-cli": "^0.4.2",
|
||||||
@@ -91,7 +89,6 @@
|
|||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"stripe": "^17.5.0",
|
"stripe": "^17.5.0",
|
||||||
"tmp-promise": "^3.0.3",
|
"tmp-promise": "^3.0.3",
|
||||||
"typesense": "^2.1.0",
|
|
||||||
"ws": "^8.18.2",
|
"ws": "^8.18.2",
|
||||||
"yauzl": "^3.2.0"
|
"yauzl": "^3.2.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import { ExportModule } from './integrations/export/export.module';
|
|||||||
import { ImportModule } from './integrations/import/import.module';
|
import { ImportModule } from './integrations/import/import.module';
|
||||||
import { SecurityModule } from './integrations/security/security.module';
|
import { SecurityModule } from './integrations/security/security.module';
|
||||||
import { TelemetryModule } from './integrations/telemetry/telemetry.module';
|
import { TelemetryModule } from './integrations/telemetry/telemetry.module';
|
||||||
import { RedisModule } from '@nestjs-labs/nestjs-ioredis';
|
|
||||||
import { RedisConfigService } from './integrations/redis/redis-config.service';
|
|
||||||
|
|
||||||
const enterpriseModules = [];
|
const enterpriseModules = [];
|
||||||
try {
|
try {
|
||||||
@@ -38,9 +36,6 @@ try {
|
|||||||
CoreModule,
|
CoreModule,
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
EnvironmentModule,
|
EnvironmentModule,
|
||||||
RedisModule.forRootAsync({
|
|
||||||
useClass: RedisConfigService,
|
|
||||||
}),
|
|
||||||
CollaborationModule,
|
CollaborationModule,
|
||||||
WsModule,
|
WsModule,
|
||||||
QueueModule,
|
QueueModule,
|
||||||
|
|||||||
@@ -33,15 +33,13 @@ import {
|
|||||||
Embed,
|
Embed,
|
||||||
Mention,
|
Mention,
|
||||||
Subpages,
|
Subpages,
|
||||||
TableOfContentsNode,
|
|
||||||
generateNodeId,
|
|
||||||
} from '@docmost/editor-ext';
|
} from '@docmost/editor-ext';
|
||||||
import { TableOfContents as TiptapTableOfContents } from '@tiptap/extension-table-of-contents';
|
|
||||||
import { generateText, getSchema, JSONContent } from '@tiptap/core';
|
import { generateText, getSchema, JSONContent } from '@tiptap/core';
|
||||||
import { generateHTML, generateJSON } from '../common/helpers/prosemirror/html';
|
import { generateHTML } from '../common/helpers/prosemirror/html';
|
||||||
// @tiptap/html library works best for generating prosemirror json state but not HTML
|
// @tiptap/html library works best for generating prosemirror json state but not HTML
|
||||||
// see: https://github.com/ueberdosis/tiptap/issues/5352
|
// see: https://github.com/ueberdosis/tiptap/issues/5352
|
||||||
// see:https://github.com/ueberdosis/tiptap/issues/4089
|
// see:https://github.com/ueberdosis/tiptap/issues/4089
|
||||||
|
import { generateJSON } from '@tiptap/html';
|
||||||
import { Node } from '@tiptap/pm/model';
|
import { Node } from '@tiptap/pm/model';
|
||||||
|
|
||||||
export const tiptapExtensions = [
|
export const tiptapExtensions = [
|
||||||
@@ -83,10 +81,6 @@ export const tiptapExtensions = [
|
|||||||
Embed,
|
Embed,
|
||||||
Mention,
|
Mention,
|
||||||
Subpages,
|
Subpages,
|
||||||
TableOfContentsNode,
|
|
||||||
TiptapTableOfContents.configure({
|
|
||||||
getId: () => generateNodeId(),
|
|
||||||
}),
|
|
||||||
] as any;
|
] as any;
|
||||||
|
|
||||||
export function jsonToHtml(tiptapJson: any) {
|
export function jsonToHtml(tiptapJson: any) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
|||||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||||
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
||||||
import { findHighestUserSpaceRole } from '@docmost/db/repos/space/utils';
|
import { findHighestUserSpaceRole } from '@docmost/db/repos/space/utils';
|
||||||
import { SpaceRole } from '../../common/helpers/types/permission';
|
import { SpaceRole, UserRole } from '../../common/helpers/types/permission';
|
||||||
import { getPageId } from '../collaboration.util';
|
import { getPageId } from '../collaboration.util';
|
||||||
import { JwtCollabPayload, JwtType } from '../../core/auth/dto/jwt-payload';
|
import { JwtCollabPayload, JwtType } from '../../core/auth/dto/jwt-payload';
|
||||||
|
|
||||||
@@ -63,7 +63,10 @@ export class AuthenticationExtension implements Extension {
|
|||||||
|
|
||||||
const userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
const userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
||||||
|
|
||||||
if (!userSpaceRole) {
|
// if role not found but user is a workspace owner, grant them readonly permission
|
||||||
|
if (!userSpaceRole && user.role === UserRole.OWNER) {
|
||||||
|
data.connection.readOnly = true;
|
||||||
|
} else if (!userSpaceRole) {
|
||||||
this.logger.warn(`User not authorized to access page: ${pageId}`);
|
this.logger.warn(`User not authorized to access page: ${pageId}`);
|
||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
export enum EventName {
|
export enum EventName {
|
||||||
COLLAB_PAGE_UPDATED = 'collab.page.updated',
|
COLLAB_PAGE_UPDATED = 'collab.page.updated',
|
||||||
PAGE_CREATED = 'page.created',
|
}
|
||||||
PAGE_UPDATED = 'page.updated',
|
|
||||||
PAGE_DELETED = 'page.deleted',
|
|
||||||
PAGE_SOFT_DELETED = 'page.soft_deleted',
|
|
||||||
PAGE_RESTORED = 'page.restored',
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,21 @@
|
|||||||
import { type Extensions, type JSONContent, getSchema } from '@tiptap/core';
|
import { Extensions, getSchema, JSONContent } from '@tiptap/core';
|
||||||
import { Node } from '@tiptap/pm/model';
|
import { DOMSerializer, Node } from '@tiptap/pm/model';
|
||||||
import { getHTMLFromFragment } from './getHTMLFromFragment';
|
import { Window } from 'happy-dom';
|
||||||
|
|
||||||
/**
|
|
||||||
* This function generates HTML from a ProseMirror JSON content object.
|
|
||||||
*
|
|
||||||
* @remarks **Important**: This function requires `happy-dom` to be installed in your project.
|
|
||||||
* @param doc - The ProseMirror JSON content object.
|
|
||||||
* @param extensions - The Tiptap extensions used to build the schema.
|
|
||||||
* @returns The generated HTML string.
|
|
||||||
* @example
|
|
||||||
* ```js
|
|
||||||
* const html = generateHTML(doc, extensions)
|
|
||||||
* console.log(html)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function generateHTML(doc: JSONContent, extensions: Extensions): string {
|
export function generateHTML(doc: JSONContent, extensions: Extensions): string {
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
throw new Error(
|
|
||||||
'generateHTML can only be used in a Node environment\nIf you want to use this in a browser environment, use the `@tiptap/html` import instead.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const schema = getSchema(extensions);
|
const schema = getSchema(extensions);
|
||||||
const contentNode = Node.fromJSON(schema, doc);
|
const contentNode = Node.fromJSON(schema, doc);
|
||||||
|
|
||||||
return getHTMLFromFragment(contentNode, schema);
|
const window = new Window();
|
||||||
|
|
||||||
|
const fragment = DOMSerializer.fromSchema(schema).serializeFragment(
|
||||||
|
contentNode.content,
|
||||||
|
{
|
||||||
|
document: window.document as unknown as Document,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const serializer = new window.XMLSerializer();
|
||||||
|
// @ts-ignore
|
||||||
|
return serializer.serializeToString(fragment as unknown as Node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,21 @@
|
|||||||
import type { Extensions } from '@tiptap/core';
|
import { Extensions, getSchema } from '@tiptap/core';
|
||||||
import { getSchema } from '@tiptap/core';
|
import { DOMParser, ParseOptions } from '@tiptap/pm/model';
|
||||||
import { type ParseOptions, DOMParser as PMDOMParser } from '@tiptap/pm/model';
|
|
||||||
import { Window } from 'happy-dom';
|
import { Window } from 'happy-dom';
|
||||||
|
|
||||||
/**
|
// this function does not work as intended
|
||||||
* Generates a JSON object from the given HTML string and converts it into a Prosemirror node with content.
|
// it has issues with closing tags
|
||||||
* @remarks **Important**: This function requires `happy-dom` to be installed in your project.
|
|
||||||
* @param {string} html - The HTML string to be converted into a Prosemirror node.
|
|
||||||
* @param {Extensions} extensions - The extensions to be used for generating the schema.
|
|
||||||
* @param {ParseOptions} options - The options to be supplied to the parser.
|
|
||||||
* @returns {Promise<Record<string, any>>} - A promise with the generated JSON object.
|
|
||||||
* @example
|
|
||||||
* const html = '<p>Hello, world!</p>'
|
|
||||||
* const extensions = [...]
|
|
||||||
* const json = generateJSON(html, extensions)
|
|
||||||
* console.log(json) // { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }] }
|
|
||||||
*/
|
|
||||||
export function generateJSON(
|
export function generateJSON(
|
||||||
html: string,
|
html: string,
|
||||||
extensions: Extensions,
|
extensions: Extensions,
|
||||||
options?: ParseOptions,
|
options?: ParseOptions,
|
||||||
): Record<string, any> {
|
): Record<string, any> {
|
||||||
if (typeof window !== 'undefined') {
|
const schema = getSchema(extensions);
|
||||||
throw new Error(
|
|
||||||
'generateJSON can only be used in a Node environment\nIf you want to use this in a browser environment, use the `@tiptap/html` import instead.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const localWindow = new Window();
|
const window = new Window();
|
||||||
const localDOMParser = new localWindow.DOMParser();
|
const document = window.document;
|
||||||
let result: Record<string, any>;
|
document.body.innerHTML = html;
|
||||||
|
|
||||||
try {
|
return DOMParser.fromSchema(schema)
|
||||||
const schema = getSchema(extensions);
|
.parse(document as never, options)
|
||||||
let doc: ReturnType<typeof localDOMParser.parseFromString> | null = null;
|
.toJSON();
|
||||||
|
|
||||||
const htmlString = `<!DOCTYPE html><html><body>${html}</body></html>`;
|
|
||||||
doc = localDOMParser.parseFromString(htmlString, 'text/html');
|
|
||||||
|
|
||||||
if (!doc) {
|
|
||||||
throw new Error('Failed to parse HTML string');
|
|
||||||
}
|
|
||||||
|
|
||||||
result = PMDOMParser.fromSchema(schema)
|
|
||||||
.parse(doc.body as unknown as Node, options)
|
|
||||||
.toJSON();
|
|
||||||
} finally {
|
|
||||||
// clean up happy-dom to avoid memory leaks
|
|
||||||
localWindow.happyDOM.abort();
|
|
||||||
localWindow.happyDOM.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
import type { Node, Schema } from '@tiptap/pm/model';
|
|
||||||
import { DOMSerializer } from '@tiptap/pm/model';
|
|
||||||
import { Window } from 'happy-dom';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the HTML string representation of a given document node.
|
|
||||||
*
|
|
||||||
* @remarks **Important**: This function requires `happy-dom` to be installed in your project.
|
|
||||||
* @param doc - The document node to serialize.
|
|
||||||
* @param schema - The Prosemirror schema to use for serialization.
|
|
||||||
* @returns A promise containing the HTML string representation of the document fragment.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```typescript
|
|
||||||
* const html = getHTMLFromFragment(doc, schema)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function getHTMLFromFragment(
|
|
||||||
doc: Node,
|
|
||||||
schema: Schema,
|
|
||||||
options?: { document?: Document },
|
|
||||||
): string {
|
|
||||||
if (options?.document) {
|
|
||||||
const wrap = options.document.createElement('div');
|
|
||||||
|
|
||||||
DOMSerializer.fromSchema(schema).serializeFragment(
|
|
||||||
doc.content,
|
|
||||||
{ document: options.document },
|
|
||||||
wrap,
|
|
||||||
);
|
|
||||||
return wrap.innerHTML;
|
|
||||||
}
|
|
||||||
|
|
||||||
const localWindow = new Window();
|
|
||||||
let result: string;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const fragment = DOMSerializer.fromSchema(schema).serializeFragment(
|
|
||||||
doc.content,
|
|
||||||
{
|
|
||||||
document: localWindow.document as unknown as Document,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const serializer = new localWindow.XMLSerializer();
|
|
||||||
result = serializer.serializeToString(fragment as any);
|
|
||||||
} finally {
|
|
||||||
// clean up happy-dom to avoid memory leaks
|
|
||||||
localWindow.happyDOM.abort();
|
|
||||||
localWindow.happyDOM.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// MIT - https://github.com/typestack/class-validator/pull/2626
|
|
||||||
import isISO6391Validator from 'validator/lib/isISO6391';
|
|
||||||
import { buildMessage, ValidateBy, ValidationOptions } from 'class-validator';
|
|
||||||
|
|
||||||
export const IS_ISO6391 = 'isISO6391';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the string is a valid [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) officially assigned language code.
|
|
||||||
*/
|
|
||||||
export function isISO6391(value: unknown): boolean {
|
|
||||||
return typeof value === 'string' && isISO6391Validator(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the string is a valid [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) officially assigned language code.
|
|
||||||
*/
|
|
||||||
export function IsISO6391(
|
|
||||||
validationOptions?: ValidationOptions,
|
|
||||||
): PropertyDecorator {
|
|
||||||
return ValidateBy(
|
|
||||||
{
|
|
||||||
name: IS_ISO6391,
|
|
||||||
validator: {
|
|
||||||
validate: (value, args): boolean => isISO6391(value),
|
|
||||||
defaultMessage: buildMessage(
|
|
||||||
(eachPrefix) =>
|
|
||||||
eachPrefix + '$property must be a valid ISO 639-1 language code',
|
|
||||||
validationOptions,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
validationOptions,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ export enum JwtType {
|
|||||||
EXCHANGE = 'exchange',
|
EXCHANGE = 'exchange',
|
||||||
ATTACHMENT = 'attachment',
|
ATTACHMENT = 'attachment',
|
||||||
MFA_TOKEN = 'mfa_token',
|
MFA_TOKEN = 'mfa_token',
|
||||||
API_KEY = 'api_key',
|
|
||||||
}
|
}
|
||||||
export type JwtPayload = {
|
export type JwtPayload = {
|
||||||
sub: string;
|
sub: string;
|
||||||
@@ -37,10 +36,3 @@ export interface JwtMfaTokenPayload {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
type: 'mfa_token';
|
type: 'mfa_token';
|
||||||
}
|
}
|
||||||
|
|
||||||
export type JwtApiKeyPayload = {
|
|
||||||
sub: string;
|
|
||||||
workspaceId: string;
|
|
||||||
apiKeyId: string;
|
|
||||||
type: 'api_key';
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import { EnvironmentService } from '../../../integrations/environment/environment.service';
|
import { EnvironmentService } from '../../../integrations/environment/environment.service';
|
||||||
import {
|
import {
|
||||||
JwtApiKeyPayload,
|
|
||||||
JwtAttachmentPayload,
|
JwtAttachmentPayload,
|
||||||
JwtCollabPayload,
|
JwtCollabPayload,
|
||||||
JwtExchangePayload,
|
JwtExchangePayload,
|
||||||
@@ -78,7 +77,10 @@ export class TokenService {
|
|||||||
return this.jwtService.sign(payload, { expiresIn: '1h' });
|
return this.jwtService.sign(payload, { expiresIn: '1h' });
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateMfaToken(user: User, workspaceId: string): Promise<string> {
|
async generateMfaToken(
|
||||||
|
user: User,
|
||||||
|
workspaceId: string,
|
||||||
|
): Promise<string> {
|
||||||
if (user.deactivatedAt || user.deletedAt) {
|
if (user.deactivatedAt || user.deletedAt) {
|
||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
@@ -91,27 +93,6 @@ export class TokenService {
|
|||||||
return this.jwtService.sign(payload, { expiresIn: '5m' });
|
return this.jwtService.sign(payload, { expiresIn: '5m' });
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateApiToken(opts: {
|
|
||||||
apiKeyId: string;
|
|
||||||
user: User;
|
|
||||||
workspaceId: string;
|
|
||||||
expiresIn?: string | number;
|
|
||||||
}): Promise<string> {
|
|
||||||
const { apiKeyId, user, workspaceId, expiresIn } = opts;
|
|
||||||
if (user.deactivatedAt || user.deletedAt) {
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload: JwtApiKeyPayload = {
|
|
||||||
sub: user.id,
|
|
||||||
apiKeyId: apiKeyId,
|
|
||||||
workspaceId,
|
|
||||||
type: JwtType.API_KEY,
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.jwtService.sign(payload, expiresIn ? { expiresIn } : {});
|
|
||||||
}
|
|
||||||
|
|
||||||
async verifyJwt(token: string, tokenType: string) {
|
async verifyJwt(token: string, tokenType: string) {
|
||||||
const payload = await this.jwtService.verifyAsync(token, {
|
const payload = await this.jwtService.verifyAsync(token, {
|
||||||
secret: this.environmentService.getAppSecret(),
|
secret: this.environmentService.getAppSecret(),
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ import { Injectable, Logger, UnauthorizedException } from '@nestjs/common';
|
|||||||
import { PassportStrategy } from '@nestjs/passport';
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
import { Strategy } from 'passport-jwt';
|
import { Strategy } from 'passport-jwt';
|
||||||
import { EnvironmentService } from '../../../integrations/environment/environment.service';
|
import { EnvironmentService } from '../../../integrations/environment/environment.service';
|
||||||
import { JwtApiKeyPayload, JwtPayload, JwtType } from '../dto/jwt-payload';
|
import { JwtPayload, JwtType } from '../dto/jwt-payload';
|
||||||
import { WorkspaceRepo } from '@docmost/db/repos/workspace/workspace.repo';
|
import { WorkspaceRepo } from '@docmost/db/repos/workspace/workspace.repo';
|
||||||
import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
import { UserRepo } from '@docmost/db/repos/user/user.repo';
|
||||||
import { FastifyRequest } from 'fastify';
|
import { FastifyRequest } from 'fastify';
|
||||||
import { extractBearerTokenFromHeader } from '../../../common/helpers';
|
import { extractBearerTokenFromHeader } from '../../../common/helpers';
|
||||||
import { ModuleRef } from '@nestjs/core';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||||
@@ -17,7 +16,6 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
private userRepo: UserRepo,
|
private userRepo: UserRepo,
|
||||||
private workspaceRepo: WorkspaceRepo,
|
private workspaceRepo: WorkspaceRepo,
|
||||||
private readonly environmentService: EnvironmentService,
|
private readonly environmentService: EnvironmentService,
|
||||||
private moduleRef: ModuleRef,
|
|
||||||
) {
|
) {
|
||||||
super({
|
super({
|
||||||
jwtFromRequest: (req: FastifyRequest) => {
|
jwtFromRequest: (req: FastifyRequest) => {
|
||||||
@@ -29,8 +27,8 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async validate(req: any, payload: JwtPayload | JwtApiKeyPayload) {
|
async validate(req: any, payload: JwtPayload) {
|
||||||
if (!payload.workspaceId) {
|
if (!payload.workspaceId || payload.type !== JwtType.ACCESS) {
|
||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,14 +36,6 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
throw new UnauthorizedException('Workspace does not match');
|
throw new UnauthorizedException('Workspace does not match');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.type === JwtType.API_KEY) {
|
|
||||||
return this.validateApiKey(req, payload as JwtApiKeyPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.type !== JwtType.ACCESS) {
|
|
||||||
throw new UnauthorizedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspace = await this.workspaceRepo.findById(payload.workspaceId);
|
const workspace = await this.workspaceRepo.findById(payload.workspaceId);
|
||||||
|
|
||||||
if (!workspace) {
|
if (!workspace) {
|
||||||
@@ -59,30 +49,4 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
|
|
||||||
return { user, workspace };
|
return { user, workspace };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validateApiKey(req: any, payload: JwtApiKeyPayload) {
|
|
||||||
let ApiKeyModule: any;
|
|
||||||
let isApiKeyModuleReady = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
||||||
ApiKeyModule = require('./../../../ee/api-key/api-key.service');
|
|
||||||
isApiKeyModuleReady = true;
|
|
||||||
} catch (err) {
|
|
||||||
this.logger.debug(
|
|
||||||
'API Key module requested but enterprise module not bundled in this build',
|
|
||||||
);
|
|
||||||
isApiKeyModuleReady = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isApiKeyModuleReady) {
|
|
||||||
const ApiKeyService = this.moduleRef.get(ApiKeyModule.ApiKeyService, {
|
|
||||||
strict: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
return ApiKeyService.validateApiKey(payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnauthorizedException('Enterprise API Key module missing');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
createMongoAbility,
|
createMongoAbility,
|
||||||
MongoAbility,
|
MongoAbility,
|
||||||
} from '@casl/ability';
|
} from '@casl/ability';
|
||||||
import { SpaceRole } from '../../../common/helpers/types/permission';
|
import { SpaceRole, UserRole } from '../../../common/helpers/types/permission';
|
||||||
import { User } from '@docmost/db/types/entity.types';
|
import { User } from '@docmost/db/types/entity.types';
|
||||||
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
||||||
import {
|
import {
|
||||||
@@ -25,13 +25,17 @@ export default class SpaceAbilityFactory {
|
|||||||
|
|
||||||
const userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
const userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
||||||
|
|
||||||
|
if (!userSpaceRole && user.role === UserRole.OWNER) {
|
||||||
|
return buildWorkspaceOwnerAbility();
|
||||||
|
}
|
||||||
|
|
||||||
switch (userSpaceRole) {
|
switch (userSpaceRole) {
|
||||||
case SpaceRole.ADMIN:
|
case SpaceRole.ADMIN:
|
||||||
return buildSpaceAdminAbility();
|
return buildSpaceAdminAbility();
|
||||||
case SpaceRole.WRITER:
|
case SpaceRole.WRITER:
|
||||||
return buildSpaceWriterAbility();
|
return buildSpaceWriterAbility(user.role);
|
||||||
case SpaceRole.READER:
|
case SpaceRole.READER:
|
||||||
return buildSpaceReaderAbility();
|
return buildSpaceReaderAbility(user.role);
|
||||||
default:
|
default:
|
||||||
throw new NotFoundException('Space permissions not found');
|
throw new NotFoundException('Space permissions not found');
|
||||||
}
|
}
|
||||||
@@ -49,23 +53,50 @@ function buildSpaceAdminAbility() {
|
|||||||
return build();
|
return build();
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSpaceWriterAbility() {
|
function buildSpaceWriterAbility(workspaceRole?: string) {
|
||||||
const { can, build } = new AbilityBuilder<MongoAbility<ISpaceAbility>>(
|
const { can, build } = new AbilityBuilder<MongoAbility<ISpaceAbility>>(
|
||||||
createMongoAbility,
|
createMongoAbility,
|
||||||
);
|
);
|
||||||
can(SpaceCaslAction.Read, SpaceCaslSubject.Settings);
|
|
||||||
can(SpaceCaslAction.Read, SpaceCaslSubject.Member);
|
if (workspaceRole === UserRole.OWNER) {
|
||||||
|
// Workspace owners get manage permissions even with writer space role
|
||||||
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Settings);
|
||||||
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Member);
|
||||||
|
} else {
|
||||||
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Settings);
|
||||||
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Member);
|
||||||
|
}
|
||||||
|
|
||||||
can(SpaceCaslAction.Manage, SpaceCaslSubject.Page);
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Page);
|
||||||
can(SpaceCaslAction.Manage, SpaceCaslSubject.Share);
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Share);
|
||||||
return build();
|
return build();
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSpaceReaderAbility() {
|
function buildSpaceReaderAbility(workspaceRole?: string) {
|
||||||
const { can, build } = new AbilityBuilder<MongoAbility<ISpaceAbility>>(
|
const { can, build } = new AbilityBuilder<MongoAbility<ISpaceAbility>>(
|
||||||
createMongoAbility,
|
createMongoAbility,
|
||||||
);
|
);
|
||||||
can(SpaceCaslAction.Read, SpaceCaslSubject.Settings);
|
|
||||||
can(SpaceCaslAction.Read, SpaceCaslSubject.Member);
|
if (workspaceRole === UserRole.OWNER) {
|
||||||
|
// Workspace owners get manage permissions even with reader space role
|
||||||
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Settings);
|
||||||
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Member);
|
||||||
|
} else {
|
||||||
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Settings);
|
||||||
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Member);
|
||||||
|
}
|
||||||
|
|
||||||
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Page);
|
||||||
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Share);
|
||||||
|
return build();
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildWorkspaceOwnerAbility() {
|
||||||
|
const { can, build } = new AbilityBuilder<MongoAbility<ISpaceAbility>>(
|
||||||
|
createMongoAbility,
|
||||||
|
);
|
||||||
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Settings);
|
||||||
|
can(SpaceCaslAction.Manage, SpaceCaslSubject.Member);
|
||||||
can(SpaceCaslAction.Read, SpaceCaslSubject.Page);
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Page);
|
||||||
can(SpaceCaslAction.Read, SpaceCaslSubject.Share);
|
can(SpaceCaslAction.Read, SpaceCaslSubject.Share);
|
||||||
return build();
|
return build();
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ function buildWorkspaceOwnerAbility() {
|
|||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Group);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Group);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Member);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Member);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Attachment);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Attachment);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.API);
|
|
||||||
|
|
||||||
return build();
|
return build();
|
||||||
}
|
}
|
||||||
@@ -56,7 +55,6 @@ function buildWorkspaceAdminAbility() {
|
|||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Group);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Group);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Member);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Member);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Attachment);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Attachment);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.API);
|
|
||||||
|
|
||||||
return build();
|
return build();
|
||||||
}
|
}
|
||||||
@@ -70,7 +68,6 @@ function buildWorkspaceMemberAbility() {
|
|||||||
can(WorkspaceCaslAction.Read, WorkspaceCaslSubject.Space);
|
can(WorkspaceCaslAction.Read, WorkspaceCaslSubject.Space);
|
||||||
can(WorkspaceCaslAction.Read, WorkspaceCaslSubject.Group);
|
can(WorkspaceCaslAction.Read, WorkspaceCaslSubject.Group);
|
||||||
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Attachment);
|
can(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Attachment);
|
||||||
can(WorkspaceCaslAction.Create, WorkspaceCaslSubject.API);
|
|
||||||
|
|
||||||
return build();
|
return build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export enum WorkspaceCaslSubject {
|
|||||||
Space = 'space',
|
Space = 'space',
|
||||||
Group = 'group',
|
Group = 'group',
|
||||||
Attachment = 'attachment',
|
Attachment = 'attachment',
|
||||||
API = 'api_key',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IWorkspaceAbility =
|
export type IWorkspaceAbility =
|
||||||
@@ -19,5 +18,4 @@ export type IWorkspaceAbility =
|
|||||||
| [WorkspaceCaslAction, WorkspaceCaslSubject.Member]
|
| [WorkspaceCaslAction, WorkspaceCaslSubject.Member]
|
||||||
| [WorkspaceCaslAction, WorkspaceCaslSubject.Space]
|
| [WorkspaceCaslAction, WorkspaceCaslSubject.Space]
|
||||||
| [WorkspaceCaslAction, WorkspaceCaslSubject.Group]
|
| [WorkspaceCaslAction, WorkspaceCaslSubject.Group]
|
||||||
| [WorkspaceCaslAction, WorkspaceCaslSubject.Attachment]
|
| [WorkspaceCaslAction, WorkspaceCaslSubject.Attachment];
|
||||||
| [WorkspaceCaslAction, WorkspaceCaslSubject.API];
|
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ import { StorageModule } from '../../integrations/storage/storage.module';
|
|||||||
controllers: [PageController],
|
controllers: [PageController],
|
||||||
providers: [PageService, PageHistoryService, TrashCleanupService],
|
providers: [PageService, PageHistoryService, TrashCleanupService],
|
||||||
exports: [PageService, PageHistoryService],
|
exports: [PageService, PageHistoryService],
|
||||||
imports: [StorageModule],
|
imports: [StorageModule]
|
||||||
})
|
})
|
||||||
export class PageModule {}
|
export class PageModule {}
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ import { StorageService } from '../../../integrations/storage/storage.service';
|
|||||||
import { InjectQueue } from '@nestjs/bullmq';
|
import { InjectQueue } from '@nestjs/bullmq';
|
||||||
import { Queue } from 'bullmq';
|
import { Queue } from 'bullmq';
|
||||||
import { QueueJob, QueueName } from '../../../integrations/queue/constants';
|
import { QueueJob, QueueName } from '../../../integrations/queue/constants';
|
||||||
import { EventName } from '../../../common/events/event.contants';
|
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PageService {
|
export class PageService {
|
||||||
@@ -51,7 +49,6 @@ export class PageService {
|
|||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
private readonly storageService: StorageService,
|
private readonly storageService: StorageService,
|
||||||
@InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue,
|
@InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue,
|
||||||
private eventEmitter: EventEmitter2,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findById(
|
async findById(
|
||||||
@@ -234,28 +231,21 @@ export class PageService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update spaceId in shares
|
||||||
if (pageIds.length > 0) {
|
if (pageIds.length > 0) {
|
||||||
// update spaceId in shares
|
|
||||||
await trx
|
await trx
|
||||||
.updateTable('shares')
|
.updateTable('shares')
|
||||||
.set({ spaceId: spaceId })
|
.set({ spaceId: spaceId })
|
||||||
.where('pageId', 'in', pageIds)
|
.where('pageId', 'in', pageIds)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// Update comments
|
|
||||||
await trx
|
|
||||||
.updateTable('comments')
|
|
||||||
.set({ spaceId: spaceId })
|
|
||||||
.where('pageId', 'in', pageIds)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
// Update attachments
|
|
||||||
await this.attachmentRepo.updateAttachmentsByPageId(
|
|
||||||
{ spaceId },
|
|
||||||
pageIds,
|
|
||||||
trx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update attachments
|
||||||
|
await this.attachmentRepo.updateAttachmentsByPageId(
|
||||||
|
{ spaceId },
|
||||||
|
pageIds,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,11 +380,6 @@ export class PageService {
|
|||||||
|
|
||||||
await this.db.insertInto('pages').values(insertablePages).execute();
|
await this.db.insertInto('pages').values(insertablePages).execute();
|
||||||
|
|
||||||
const insertedPageIds = insertablePages.map((page) => page.id);
|
|
||||||
this.eventEmitter.emit(EventName.PAGE_CREATED, {
|
|
||||||
pageIds: insertedPageIds,
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO: best to handle this in a queue
|
//TODO: best to handle this in a queue
|
||||||
const attachmentsIds = Array.from(attachmentMap.keys());
|
const attachmentsIds = Array.from(attachmentMap.keys());
|
||||||
if (attachmentsIds.length > 0) {
|
if (attachmentsIds.length > 0) {
|
||||||
@@ -621,9 +606,6 @@ export class PageService {
|
|||||||
|
|
||||||
if (pageIds.length > 0) {
|
if (pageIds.length > 0) {
|
||||||
await this.db.deleteFrom('pages').where('id', 'in', pageIds).execute();
|
await this.db.deleteFrom('pages').where('id', 'in', pageIds).execute();
|
||||||
this.eventEmitter.emit(EventName.PAGE_DELETED, {
|
|
||||||
pageIds: pageIds,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { Space } from '@docmost/db/types/entity.types';
|
|
||||||
|
|
||||||
export class SearchResponseDto {
|
export class SearchResponseDto {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -10,5 +8,4 @@ export class SearchResponseDto {
|
|||||||
highlight: string;
|
highlight: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
space: Partial<Space>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Logger,
|
|
||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
@@ -25,19 +24,13 @@ import {
|
|||||||
} from '../casl/interfaces/space-ability.type';
|
} from '../casl/interfaces/space-ability.type';
|
||||||
import { AuthUser } from '../../common/decorators/auth-user.decorator';
|
import { AuthUser } from '../../common/decorators/auth-user.decorator';
|
||||||
import { Public } from 'src/common/decorators/public.decorator';
|
import { Public } from 'src/common/decorators/public.decorator';
|
||||||
import { EnvironmentService } from '../../integrations/environment/environment.service';
|
|
||||||
import { ModuleRef } from '@nestjs/core';
|
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('search')
|
@Controller('search')
|
||||||
export class SearchController {
|
export class SearchController {
|
||||||
private readonly logger = new Logger(SearchController.name);
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly searchService: SearchService,
|
private readonly searchService: SearchService,
|
||||||
private readonly spaceAbility: SpaceAbilityFactory,
|
private readonly spaceAbility: SpaceAbilityFactory,
|
||||||
private readonly environmentService: EnvironmentService,
|
|
||||||
private moduleRef: ModuleRef,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@@ -60,14 +53,7 @@ export class SearchController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.environmentService.getSearchDriver() === 'typesense') {
|
return this.searchService.searchPage(searchDto.query, searchDto, {
|
||||||
return this.searchTypesense(searchDto, {
|
|
||||||
userId: user.id,
|
|
||||||
workspaceId: workspace.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.searchService.searchPage(searchDto, {
|
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
});
|
});
|
||||||
@@ -95,47 +81,8 @@ export class SearchController {
|
|||||||
throw new BadRequestException('shareId is required');
|
throw new BadRequestException('shareId is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.environmentService.getSearchDriver() === 'typesense') {
|
return this.searchService.searchPage(searchDto.query, searchDto, {
|
||||||
return this.searchTypesense(searchDto, {
|
|
||||||
workspaceId: workspace.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.searchService.searchPage(searchDto, {
|
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchTypesense(
|
|
||||||
searchParams: SearchDTO,
|
|
||||||
opts: {
|
|
||||||
userId?: string;
|
|
||||||
workspaceId: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const { userId, workspaceId } = opts;
|
|
||||||
let TypesenseModule: any;
|
|
||||||
try {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
||||||
TypesenseModule = require('./../../ee/typesense/services/page-search.service');
|
|
||||||
|
|
||||||
const PageSearchService = this.moduleRef.get(
|
|
||||||
TypesenseModule.PageSearchService,
|
|
||||||
{
|
|
||||||
strict: false,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return PageSearchService.searchPage(searchParams, {
|
|
||||||
userId: userId,
|
|
||||||
workspaceId,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
this.logger.debug(
|
|
||||||
'Typesense module requested but enterprise module not bundled in this build',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new BadRequestException('Enterprise Typesense search module missing');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,13 @@ export class SearchService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async searchPage(
|
async searchPage(
|
||||||
|
query: string,
|
||||||
searchParams: SearchDTO,
|
searchParams: SearchDTO,
|
||||||
opts: {
|
opts: {
|
||||||
userId?: string;
|
userId?: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
},
|
},
|
||||||
): Promise<SearchResponseDto[]> {
|
): Promise<SearchResponseDto[]> {
|
||||||
const { query } = searchParams;
|
|
||||||
|
|
||||||
if (query.length < 1) {
|
if (query.length < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,4 +279,14 @@ export class SpaceMemberService {
|
|||||||
): Promise<PaginationResult<Space>> {
|
): Promise<PaginationResult<Space>> {
|
||||||
return await this.spaceMemberRepo.getUserSpaces(userId, pagination);
|
return await this.spaceMemberRepo.getUserSpaces(userId, pagination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAllWorkspaceSpaces(
|
||||||
|
workspaceId: string,
|
||||||
|
pagination: PaginationOptions,
|
||||||
|
): Promise<PaginationResult<Space>> {
|
||||||
|
return await this.spaceMemberRepo.getAllWorkspaceSpaces(
|
||||||
|
workspaceId,
|
||||||
|
pagination,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
} from '../casl/interfaces/workspace-ability.type';
|
} from '../casl/interfaces/workspace-ability.type';
|
||||||
import WorkspaceAbilityFactory from '../casl/abilities/workspace-ability.factory';
|
import WorkspaceAbilityFactory from '../casl/abilities/workspace-ability.factory';
|
||||||
import { CreateSpaceDto } from './dto/create-space.dto';
|
import { CreateSpaceDto } from './dto/create-space.dto';
|
||||||
|
import { SpaceRole, UserRole } from '../../common/helpers/types/permission';
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('spaces')
|
@Controller('spaces')
|
||||||
@@ -52,7 +53,17 @@ export class SpaceController {
|
|||||||
@Body()
|
@Body()
|
||||||
pagination: PaginationOptions,
|
pagination: PaginationOptions,
|
||||||
@AuthUser() user: User,
|
@AuthUser() user: User,
|
||||||
|
@AuthWorkspace() workspace: Workspace,
|
||||||
) {
|
) {
|
||||||
|
if (pagination.includeAllSpaces) {
|
||||||
|
if (user.role !== UserRole.OWNER) {
|
||||||
|
throw new ForbiddenException('Only workspace owners view all spaces');
|
||||||
|
}
|
||||||
|
return this.spaceMemberService.getAllWorkspaceSpaces(
|
||||||
|
workspace.id,
|
||||||
|
pagination,
|
||||||
|
);
|
||||||
|
}
|
||||||
return this.spaceMemberService.getUserSpaces(user.id, pagination);
|
return this.spaceMemberService.getUserSpaces(user.id, pagination);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +93,10 @@ export class SpaceController {
|
|||||||
space.id,
|
space.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
const userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
let userSpaceRole = findHighestUserSpaceRole(userSpaceRoles);
|
||||||
|
if (!userSpaceRole && user.role === UserRole.OWNER) {
|
||||||
|
userSpaceRole = SpaceRole.READER;
|
||||||
|
}
|
||||||
|
|
||||||
const membership = {
|
const membership = {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
|||||||
@@ -18,8 +18,4 @@ export class UpdateWorkspaceDto extends PartialType(CreateWorkspaceDto) {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
enforceMfa: boolean;
|
enforceMfa: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
restrictApiToAdmins: boolean;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,15 +303,6 @@ export class WorkspaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof updateWorkspaceDto.restrictApiToAdmins !== 'undefined') {
|
|
||||||
await this.workspaceRepo.updateApiSettings(
|
|
||||||
workspaceId,
|
|
||||||
'restrictToAdmins',
|
|
||||||
updateWorkspaceDto.restrictApiToAdmins,
|
|
||||||
);
|
|
||||||
delete updateWorkspaceDto.restrictApiToAdmins;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.workspaceRepo.updateWorkspace(updateWorkspaceDto, workspaceId);
|
await this.workspaceRepo.updateWorkspace(updateWorkspaceDto, workspaceId);
|
||||||
|
|
||||||
const workspace = await this.workspaceRepo.findById(workspaceId, {
|
const workspace = await this.workspaceRepo.findById(workspaceId, {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import { MigrationService } from '@docmost/db/services/migration.service';
|
|||||||
import { UserTokenRepo } from './repos/user-token/user-token.repo';
|
import { UserTokenRepo } from './repos/user-token/user-token.repo';
|
||||||
import { BacklinkRepo } from '@docmost/db/repos/backlink/backlink.repo';
|
import { BacklinkRepo } from '@docmost/db/repos/backlink/backlink.repo';
|
||||||
import { ShareRepo } from '@docmost/db/repos/share/share.repo';
|
import { ShareRepo } from '@docmost/db/repos/share/share.repo';
|
||||||
import { PageListener } from '@docmost/db/listeners/page.listener';
|
|
||||||
|
|
||||||
// https://github.com/brianc/node-postgres/issues/811
|
// https://github.com/brianc/node-postgres/issues/811
|
||||||
types.setTypeParser(types.builtins.INT8, (val) => Number(val));
|
types.setTypeParser(types.builtins.INT8, (val) => Number(val));
|
||||||
@@ -76,8 +75,7 @@ types.setTypeParser(types.builtins.INT8, (val) => Number(val));
|
|||||||
AttachmentRepo,
|
AttachmentRepo,
|
||||||
UserTokenRepo,
|
UserTokenRepo,
|
||||||
BacklinkRepo,
|
BacklinkRepo,
|
||||||
ShareRepo,
|
ShareRepo
|
||||||
PageListener,
|
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
WorkspaceRepo,
|
WorkspaceRepo,
|
||||||
@@ -92,7 +90,7 @@ types.setTypeParser(types.builtins.INT8, (val) => Number(val));
|
|||||||
AttachmentRepo,
|
AttachmentRepo,
|
||||||
UserTokenRepo,
|
UserTokenRepo,
|
||||||
BacklinkRepo,
|
BacklinkRepo,
|
||||||
ShareRepo,
|
ShareRepo
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class DatabaseModule
|
export class DatabaseModule
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
|
||||||
import { OnEvent } from '@nestjs/event-emitter';
|
|
||||||
import { EventName } from '../../common/events/event.contants';
|
|
||||||
import { InjectQueue } from '@nestjs/bullmq';
|
|
||||||
import { QueueJob, QueueName } from '../../integrations/queue/constants';
|
|
||||||
import { Queue } from 'bullmq';
|
|
||||||
|
|
||||||
export class PageEvent {
|
|
||||||
pageIds: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class PageListener {
|
|
||||||
private readonly logger = new Logger(PageListener.name);
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@InjectQueue(QueueName.SEARCH_QUEUE) private searchQueue: Queue,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@OnEvent(EventName.PAGE_CREATED)
|
|
||||||
async handlePageCreated(event: PageEvent) {
|
|
||||||
const { pageIds } = event;
|
|
||||||
await this.searchQueue.add(QueueJob.PAGE_CREATED, { pageIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnEvent(EventName.PAGE_UPDATED)
|
|
||||||
async handlePageUpdated(event: PageEvent) {
|
|
||||||
const { pageIds } = event;
|
|
||||||
await this.searchQueue.add(QueueJob.PAGE_UPDATED, { pageIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnEvent(EventName.PAGE_DELETED)
|
|
||||||
async handlePageDeleted(event: PageEvent) {
|
|
||||||
const { pageIds } = event;
|
|
||||||
await this.searchQueue.add(QueueJob.PAGE_DELETED, { pageIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnEvent(EventName.PAGE_SOFT_DELETED)
|
|
||||||
async handlePageSoftDeleted(event: PageEvent) {
|
|
||||||
const { pageIds } = event;
|
|
||||||
await this.searchQueue.add(QueueJob.PAGE_SOFT_DELETED, { pageIds });
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnEvent(EventName.PAGE_RESTORED)
|
|
||||||
async handlePageRestored(event: PageEvent) {
|
|
||||||
const { pageIds } = event;
|
|
||||||
await this.searchQueue.add(QueueJob.PAGE_RESTORED, { pageIds });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { Kysely, sql } from 'kysely';
|
|
||||||
|
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
|
||||||
await db.schema
|
|
||||||
.createTable('api_keys')
|
|
||||||
.addColumn('id', 'uuid', (col) =>
|
|
||||||
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
|
||||||
)
|
|
||||||
.addColumn('name', 'text', (col) => col)
|
|
||||||
.addColumn('creator_id', 'uuid', (col) =>
|
|
||||||
col.notNull().references('users.id').onDelete('cascade'),
|
|
||||||
)
|
|
||||||
.addColumn('workspace_id', 'uuid', (col) =>
|
|
||||||
col.notNull().references('workspaces.id').onDelete('cascade'),
|
|
||||||
)
|
|
||||||
.addColumn('expires_at', 'timestamptz')
|
|
||||||
.addColumn('last_used_at', 'timestamptz')
|
|
||||||
.addColumn('created_at', 'timestamptz', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
|
||||||
)
|
|
||||||
.addColumn('updated_at', 'timestamptz', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
|
||||||
)
|
|
||||||
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
|
||||||
await db.schema.dropTable('api_keys').execute();
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,8 @@ export class PaginationOptions {
|
|||||||
@IsString()
|
@IsString()
|
||||||
query: string;
|
query: string;
|
||||||
|
|
||||||
|
//for space endpoint workspace owners
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
adminView: boolean;
|
includeAllSpaces?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,32 @@ import { ExpressionBuilder, sql } from 'kysely';
|
|||||||
import { DB } from '@docmost/db/types/db';
|
import { DB } from '@docmost/db/types/db';
|
||||||
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
||||||
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
import { SpaceMemberRepo } from '@docmost/db/repos/space/space-member.repo';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
||||||
import { EventName } from '../../../common/events/event.contants';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PageRepo {
|
export class PageRepo {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
private spaceMemberRepo: SpaceMemberRepo,
|
private spaceMemberRepo: SpaceMemberRepo,
|
||||||
private eventEmitter: EventEmitter2,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
withHasChildren(eb: ExpressionBuilder<DB, 'pages'>) {
|
||||||
|
return eb
|
||||||
|
.selectFrom('pages as child')
|
||||||
|
.select((eb) =>
|
||||||
|
eb
|
||||||
|
.case()
|
||||||
|
.when(eb.fn.countAll(), '>', 0)
|
||||||
|
.then(true)
|
||||||
|
.else(false)
|
||||||
|
.end()
|
||||||
|
.as('count'),
|
||||||
|
)
|
||||||
|
.whereRef('child.parentPageId', '=', 'pages.id')
|
||||||
|
.where('child.deletedAt', 'is', null)
|
||||||
|
.limit(1)
|
||||||
|
.as('hasChildren');
|
||||||
|
}
|
||||||
|
|
||||||
private baseFields: Array<keyof Page> = [
|
private baseFields: Array<keyof Page> = [
|
||||||
'id',
|
'id',
|
||||||
'slugId',
|
'slugId',
|
||||||
@@ -48,7 +63,6 @@ export class PageRepo {
|
|||||||
pageId: string,
|
pageId: string,
|
||||||
opts?: {
|
opts?: {
|
||||||
includeContent?: boolean;
|
includeContent?: boolean;
|
||||||
includeTextContent?: boolean;
|
|
||||||
includeYdoc?: boolean;
|
includeYdoc?: boolean;
|
||||||
includeSpace?: boolean;
|
includeSpace?: boolean;
|
||||||
includeCreator?: boolean;
|
includeCreator?: boolean;
|
||||||
@@ -66,7 +80,6 @@ export class PageRepo {
|
|||||||
.select(this.baseFields)
|
.select(this.baseFields)
|
||||||
.$if(opts?.includeContent, (qb) => qb.select('content'))
|
.$if(opts?.includeContent, (qb) => qb.select('content'))
|
||||||
.$if(opts?.includeYdoc, (qb) => qb.select('ydoc'))
|
.$if(opts?.includeYdoc, (qb) => qb.select('ydoc'))
|
||||||
.$if(opts?.includeTextContent, (qb) => qb.select('textContent'))
|
|
||||||
.$if(opts?.includeHasChildren, (qb) =>
|
.$if(opts?.includeHasChildren, (qb) =>
|
||||||
qb.select((eb) => this.withHasChildren(eb)),
|
qb.select((eb) => this.withHasChildren(eb)),
|
||||||
);
|
);
|
||||||
@@ -113,7 +126,7 @@ export class PageRepo {
|
|||||||
pageIds: string[],
|
pageIds: string[],
|
||||||
trx?: KyselyTransaction,
|
trx?: KyselyTransaction,
|
||||||
) {
|
) {
|
||||||
const result = await dbOrTx(this.db, trx)
|
return dbOrTx(this.db, trx)
|
||||||
.updateTable('pages')
|
.updateTable('pages')
|
||||||
.set({ ...updatePageData, updatedAt: new Date() })
|
.set({ ...updatePageData, updatedAt: new Date() })
|
||||||
.where(
|
.where(
|
||||||
@@ -122,12 +135,6 @@ export class PageRepo {
|
|||||||
pageIds,
|
pageIds,
|
||||||
)
|
)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
|
||||||
pageIds: pageIds,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async insertPage(
|
async insertPage(
|
||||||
@@ -135,17 +142,11 @@ export class PageRepo {
|
|||||||
trx?: KyselyTransaction,
|
trx?: KyselyTransaction,
|
||||||
): Promise<Page> {
|
): Promise<Page> {
|
||||||
const db = dbOrTx(this.db, trx);
|
const db = dbOrTx(this.db, trx);
|
||||||
const result = await db
|
return db
|
||||||
.insertInto('pages')
|
.insertInto('pages')
|
||||||
.values(insertablePage)
|
.values(insertablePage)
|
||||||
.returning(this.baseFields)
|
.returning(this.baseFields)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|
||||||
this.eventEmitter.emit(EventName.PAGE_CREATED, {
|
|
||||||
pageIds: [result.id],
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deletePage(pageId: string): Promise<void> {
|
async deletePage(pageId: string): Promise<void> {
|
||||||
@@ -195,9 +196,6 @@ export class PageRepo {
|
|||||||
|
|
||||||
await trx.deleteFrom('shares').where('pageId', 'in', pageIds).execute();
|
await trx.deleteFrom('shares').where('pageId', 'in', pageIds).execute();
|
||||||
});
|
});
|
||||||
this.eventEmitter.emit(EventName.PAGE_SOFT_DELETED, {
|
|
||||||
pageIds: pageIds,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,9 +259,6 @@ export class PageRepo {
|
|||||||
.where('id', '=', pageId)
|
.where('id', '=', pageId)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
this.eventEmitter.emit(EventName.PAGE_RESTORED, {
|
|
||||||
pageIds: pageIds,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRecentPagesInSpace(spaceId: string, pagination: PaginationOptions) {
|
async getRecentPagesInSpace(spaceId: string, pagination: PaginationOptions) {
|
||||||
@@ -384,24 +379,6 @@ export class PageRepo {
|
|||||||
).as('contributors');
|
).as('contributors');
|
||||||
}
|
}
|
||||||
|
|
||||||
withHasChildren(eb: ExpressionBuilder<DB, 'pages'>) {
|
|
||||||
return eb
|
|
||||||
.selectFrom('pages as child')
|
|
||||||
.select((eb) =>
|
|
||||||
eb
|
|
||||||
.case()
|
|
||||||
.when(eb.fn.countAll(), '>', 0)
|
|
||||||
.then(true)
|
|
||||||
.else(false)
|
|
||||||
.end()
|
|
||||||
.as('count'),
|
|
||||||
)
|
|
||||||
.whereRef('child.parentPageId', '=', 'pages.id')
|
|
||||||
.where('child.deletedAt', 'is', null)
|
|
||||||
.limit(1)
|
|
||||||
.as('hasChildren');
|
|
||||||
}
|
|
||||||
|
|
||||||
async getPageAndDescendants(
|
async getPageAndDescendants(
|
||||||
parentPageId: string,
|
parentPageId: string,
|
||||||
opts: { includeContent: boolean },
|
opts: { includeContent: boolean },
|
||||||
|
|||||||
@@ -263,4 +263,37 @@ export class SpaceMemberRepo {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAllWorkspaceSpaces(
|
||||||
|
workspaceId: string,
|
||||||
|
pagination: PaginationOptions,
|
||||||
|
) {
|
||||||
|
let query = this.db
|
||||||
|
.selectFrom('spaces')
|
||||||
|
.selectAll()
|
||||||
|
.select((eb) => [this.spaceRepo.withMemberCount(eb)])
|
||||||
|
.where('workspaceId', '=', workspaceId)
|
||||||
|
.orderBy('createdAt', 'asc');
|
||||||
|
|
||||||
|
if (pagination.query) {
|
||||||
|
query = query.where((eb) =>
|
||||||
|
eb(
|
||||||
|
sql`f_unaccent(name)`,
|
||||||
|
'ilike',
|
||||||
|
sql`f_unaccent(${'%' + pagination.query + '%'})`,
|
||||||
|
).or(
|
||||||
|
sql`f_unaccent(description)`,
|
||||||
|
'ilike',
|
||||||
|
sql`f_unaccent(${'%' + pagination.query + '%'})`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = executeWithPagination(query, {
|
||||||
|
page: pagination.page,
|
||||||
|
perPage: pagination.limit,
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,22 +157,4 @@ export class WorkspaceRepo {
|
|||||||
|
|
||||||
return activeUsers.length;
|
return activeUsers.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateApiSettings(
|
|
||||||
workspaceId: string,
|
|
||||||
prefKey: string,
|
|
||||||
prefValue: string | boolean,
|
|
||||||
) {
|
|
||||||
return this.db
|
|
||||||
.updateTable('workspaces')
|
|
||||||
.set({
|
|
||||||
settings: sql`COALESCE(settings, '{}'::jsonb)
|
|
||||||
|| jsonb_build_object('api', COALESCE(settings->'api', '{}'::jsonb)
|
|
||||||
|| jsonb_build_object('${sql.raw(prefKey)}', ${sql.lit(prefValue)}))`,
|
|
||||||
updatedAt: new Date(),
|
|
||||||
})
|
|
||||||
.where('id', '=', workspaceId)
|
|
||||||
.returning(this.baseFields)
|
|
||||||
.executeTakeFirst();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-23
@@ -3,18 +3,13 @@
|
|||||||
* Please do not edit it manually.
|
* Please do not edit it manually.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ColumnType } from 'kysely';
|
import type { ColumnType } from "kysely";
|
||||||
|
|
||||||
export type Generated<T> =
|
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
|
||||||
T extends ColumnType<infer S, infer I, infer U>
|
? ColumnType<S, I | undefined, U>
|
||||||
? ColumnType<S, I | undefined, U>
|
: ColumnType<T, T | undefined, T>;
|
||||||
: ColumnType<T, T | undefined, T>;
|
|
||||||
|
|
||||||
export type Int8 = ColumnType<
|
export type Int8 = ColumnType<string, bigint | number | string, bigint | number | string>;
|
||||||
string,
|
|
||||||
bigint | number | string,
|
|
||||||
bigint | number | string
|
|
||||||
>;
|
|
||||||
|
|
||||||
export type Json = JsonValue;
|
export type Json = JsonValue;
|
||||||
|
|
||||||
@@ -30,18 +25,6 @@ export type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|||||||
|
|
||||||
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
|
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
|
||||||
|
|
||||||
export interface ApiKeys {
|
|
||||||
createdAt: Generated<Timestamp>;
|
|
||||||
deletedAt: Timestamp | null;
|
|
||||||
expiresAt: Timestamp | null;
|
|
||||||
id: Generated<string>;
|
|
||||||
lastUsedAt: Timestamp | null;
|
|
||||||
name: string | null;
|
|
||||||
updatedAt: Generated<Timestamp>;
|
|
||||||
creatorId: string;
|
|
||||||
workspaceId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Attachments {
|
export interface Attachments {
|
||||||
createdAt: Generated<Timestamp>;
|
createdAt: Generated<Timestamp>;
|
||||||
creatorId: string;
|
creatorId: string;
|
||||||
@@ -361,7 +344,6 @@ export interface Workspaces {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DB {
|
export interface DB {
|
||||||
apiKeys: ApiKeys;
|
|
||||||
attachments: Attachments;
|
attachments: Attachments;
|
||||||
authAccounts: AuthAccounts;
|
authAccounts: AuthAccounts;
|
||||||
authProviders: AuthProviders;
|
authProviders: AuthProviders;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
Shares,
|
Shares,
|
||||||
FileTasks,
|
FileTasks,
|
||||||
UserMfa as _UserMFA,
|
UserMfa as _UserMFA,
|
||||||
ApiKeys,
|
|
||||||
} from './db';
|
} from './db';
|
||||||
|
|
||||||
// Workspace
|
// Workspace
|
||||||
@@ -120,8 +119,3 @@ export type UpdatableFileTask = Updateable<Omit<FileTasks, 'id'>>;
|
|||||||
export type UserMFA = Selectable<_UserMFA>;
|
export type UserMFA = Selectable<_UserMFA>;
|
||||||
export type InsertableUserMFA = Insertable<_UserMFA>;
|
export type InsertableUserMFA = Insertable<_UserMFA>;
|
||||||
export type UpdatableUserMFA = Updateable<Omit<_UserMFA, 'id'>>;
|
export type UpdatableUserMFA = Updateable<Omit<_UserMFA, 'id'>>;
|
||||||
|
|
||||||
// Api Keys
|
|
||||||
export type ApiKey = Selectable<ApiKeys>;
|
|
||||||
export type InsertableApiKey = Insertable<ApiKeys>;
|
|
||||||
export type UpdatableApiKey = Updateable<Omit<ApiKeys, 'id'>>;
|
|
||||||
|
|||||||
+1
-1
Submodule apps/server/src/ee updated: 9957da11d6...3af21def15
@@ -213,24 +213,4 @@ export class EnvironmentService {
|
|||||||
getPostHogKey(): string {
|
getPostHogKey(): string {
|
||||||
return this.configService.get<string>('POSTHOG_KEY');
|
return this.configService.get<string>('POSTHOG_KEY');
|
||||||
}
|
}
|
||||||
|
|
||||||
getSearchDriver(): string {
|
|
||||||
return this.configService
|
|
||||||
.get<string>('SEARCH_DRIVER', 'database')
|
|
||||||
.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
getTypesenseUrl(): string {
|
|
||||||
return this.configService
|
|
||||||
.get<string>('TYPESENSE_URL', 'http://localhost:8108')
|
|
||||||
.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
getTypesenseApiKey(): string {
|
|
||||||
return this.configService.get<string>('TYPESENSE_API_KEY');
|
|
||||||
}
|
|
||||||
|
|
||||||
getTypesenseLocale(): string {
|
|
||||||
return this.configService.get<string>('TYPESENSE_LOCALE', 'en').toLowerCase();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,12 @@ import {
|
|||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsNotIn,
|
IsNotIn,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
|
||||||
IsUrl,
|
IsUrl,
|
||||||
MinLength,
|
MinLength,
|
||||||
ValidateIf,
|
ValidateIf,
|
||||||
validateSync,
|
validateSync,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { plainToInstance } from 'class-transformer';
|
import { plainToInstance } from 'class-transformer';
|
||||||
import { IsISO6391 } from '../../common/validator/is-iso6391';
|
|
||||||
|
|
||||||
export class EnvironmentVariables {
|
export class EnvironmentVariables {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -70,37 +68,6 @@ export class EnvironmentVariables {
|
|||||||
)
|
)
|
||||||
@ValidateIf((obj) => obj.CLOUD === 'true'.toLowerCase())
|
@ValidateIf((obj) => obj.CLOUD === 'true'.toLowerCase())
|
||||||
SUBDOMAIN_HOST: string;
|
SUBDOMAIN_HOST: string;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsIn(['database', 'typesense'])
|
|
||||||
@IsString()
|
|
||||||
SEARCH_DRIVER: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsUrl(
|
|
||||||
{
|
|
||||||
protocols: ['http', 'https'],
|
|
||||||
require_tld: false,
|
|
||||||
allow_underscores: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message:
|
|
||||||
'TYPESENSE_URL must be a valid typesense url e.g http://localhost:8108',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
@ValidateIf((obj) => obj.SEARCH_DRIVER === 'typesense')
|
|
||||||
TYPESENSE_URL: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@ValidateIf((obj) => obj.SEARCH_DRIVER === 'typesense')
|
|
||||||
@IsString()
|
|
||||||
TYPESENSE_API_KEY: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@ValidateIf((obj) => obj.SEARCH_DRIVER === 'typesense')
|
|
||||||
@IsISO6391()
|
|
||||||
@IsString()
|
|
||||||
TYPESENSE_LOCALE: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validate(config: Record<string, any>) {
|
export function validate(config: Record<string, any>) {
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ import { ImportAttachmentService } from './import-attachment.service';
|
|||||||
import { ModuleRef } from '@nestjs/core';
|
import { ModuleRef } from '@nestjs/core';
|
||||||
import { PageService } from '../../../core/page/services/page.service';
|
import { PageService } from '../../../core/page/services/page.service';
|
||||||
import { ImportPageNode } from '../dto/file-task-dto';
|
import { ImportPageNode } from '../dto/file-task-dto';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
||||||
import { EventName } from '../../../common/events/event.contants';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FileImportTaskService {
|
export class FileImportTaskService {
|
||||||
@@ -47,7 +45,6 @@ export class FileImportTaskService {
|
|||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
private readonly importAttachmentService: ImportAttachmentService,
|
private readonly importAttachmentService: ImportAttachmentService,
|
||||||
private moduleRef: ModuleRef,
|
private moduleRef: ModuleRef,
|
||||||
private eventEmitter: EventEmitter2,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async processZIpImport(fileTaskId: string): Promise<void> {
|
async processZIpImport(fileTaskId: string): Promise<void> {
|
||||||
@@ -399,12 +396,6 @@ export class FileImportTaskService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validPageIds.size > 0) {
|
|
||||||
this.eventEmitter.emit(EventName.PAGE_CREATED, {
|
|
||||||
pageIds: Array.from(validPageIds),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`Successfully imported ${totalPagesProcessed} pages with ${filteredBacklinks.length} backlinks`,
|
`Successfully imported ${totalPagesProcessed} pages with ${filteredBacklinks.length} backlinks`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ export enum QueueName {
|
|||||||
GENERAL_QUEUE = '{general-queue}',
|
GENERAL_QUEUE = '{general-queue}',
|
||||||
BILLING_QUEUE = '{billing-queue}',
|
BILLING_QUEUE = '{billing-queue}',
|
||||||
FILE_TASK_QUEUE = '{file-task-queue}',
|
FILE_TASK_QUEUE = '{file-task-queue}',
|
||||||
SEARCH_QUEUE = '{search-queue}',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum QueueJob {
|
export enum QueueJob {
|
||||||
@@ -26,21 +25,4 @@ export enum QueueJob {
|
|||||||
|
|
||||||
IMPORT_TASK = 'import-task',
|
IMPORT_TASK = 'import-task',
|
||||||
EXPORT_TASK = 'export-task',
|
EXPORT_TASK = 'export-task',
|
||||||
|
|
||||||
SEARCH_INDEX_PAGE = 'search-index-page',
|
|
||||||
SEARCH_INDEX_PAGES = 'search-index-pages',
|
|
||||||
SEARCH_INDEX_COMMENT = 'search-index-comment',
|
|
||||||
SEARCH_INDEX_COMMENTS = 'search-index-comments',
|
|
||||||
SEARCH_INDEX_ATTACHMENT = 'search-index-attachment',
|
|
||||||
SEARCH_INDEX_ATTACHMENTS = 'search-index-attachments',
|
|
||||||
SEARCH_REMOVE_PAGE = 'search-remove-page',
|
|
||||||
SEARCH_REMOVE_ASSET = 'search-remove-attachment',
|
|
||||||
SEARCH_REMOVE_FACE = 'search-remove-comment',
|
|
||||||
TYPESENSE_FLUSH = 'typesense-flush',
|
|
||||||
|
|
||||||
PAGE_CREATED = 'page-created',
|
|
||||||
PAGE_UPDATED = 'page-updated',
|
|
||||||
PAGE_SOFT_DELETED = 'page-soft-deleted',
|
|
||||||
PAGE_RESTORED = 'page-restored',
|
|
||||||
PAGE_DELETED = 'page-deleted',
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,14 +57,6 @@ import { BacklinksProcessor } from './processors/backlinks.processor';
|
|||||||
attempts: 1,
|
attempts: 1,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
BullModule.registerQueue({
|
|
||||||
name: QueueName.SEARCH_QUEUE,
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: true,
|
|
||||||
attempts: 2,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
exports: [BullModule],
|
exports: [BullModule],
|
||||||
providers: [BacklinksProcessor],
|
providers: [BacklinksProcessor],
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import {
|
|
||||||
RedisModuleOptions,
|
|
||||||
RedisOptionsFactory,
|
|
||||||
} from '@nestjs-labs/nestjs-ioredis';
|
|
||||||
import { createRetryStrategy, parseRedisUrl } from '../../common/helpers';
|
|
||||||
import { EnvironmentService } from '../environment/environment.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class RedisConfigService implements RedisOptionsFactory {
|
|
||||||
constructor(private readonly environmentService: EnvironmentService) {}
|
|
||||||
createRedisOptions(): RedisModuleOptions {
|
|
||||||
const redisConfig = parseRedisUrl(this.environmentService.getRedisUrl());
|
|
||||||
return {
|
|
||||||
readyLog: true,
|
|
||||||
config: {
|
|
||||||
host: redisConfig.host,
|
|
||||||
port: redisConfig.port,
|
|
||||||
password: redisConfig.password,
|
|
||||||
db: redisConfig.db,
|
|
||||||
family: redisConfig.family,
|
|
||||||
retryStrategy: createRetryStrategy(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+39
-42
@@ -21,48 +21,47 @@
|
|||||||
"@braintree/sanitize-url": "^7.1.0",
|
"@braintree/sanitize-url": "^7.1.0",
|
||||||
"@docmost/editor-ext": "workspace:*",
|
"@docmost/editor-ext": "workspace:*",
|
||||||
"@floating-ui/dom": "^1.7.3",
|
"@floating-ui/dom": "^1.7.3",
|
||||||
"@hocuspocus/extension-redis": "^2.15.3",
|
"@hocuspocus/extension-redis": "^2.15.2",
|
||||||
"@hocuspocus/provider": "^2.15.3",
|
"@hocuspocus/provider": "^2.15.2",
|
||||||
"@hocuspocus/server": "^2.15.3",
|
"@hocuspocus/server": "^2.15.2",
|
||||||
"@hocuspocus/transformer": "^2.15.3",
|
"@hocuspocus/transformer": "^2.15.2",
|
||||||
"@joplin/turndown": "^4.0.74",
|
"@joplin/turndown": "^4.0.74",
|
||||||
"@joplin/turndown-plugin-gfm": "^1.0.56",
|
"@joplin/turndown-plugin-gfm": "^1.0.56",
|
||||||
"@sindresorhus/slugify": "1.1.0",
|
"@sindresorhus/slugify": "1.1.0",
|
||||||
"@tiptap/core": "^2.27.1",
|
"@tiptap/core": "^2.10.3",
|
||||||
"@tiptap/extension-code-block": "^2.27.1",
|
"@tiptap/extension-code-block": "^2.10.3",
|
||||||
"@tiptap/extension-code-block-lowlight": "^2.27.1",
|
"@tiptap/extension-code-block-lowlight": "^2.10.3",
|
||||||
"@tiptap/extension-collaboration": "^2.27.1",
|
"@tiptap/extension-collaboration": "^2.10.3",
|
||||||
"@tiptap/extension-collaboration-cursor": "^2.27.1",
|
"@tiptap/extension-collaboration-cursor": "^2.10.3",
|
||||||
"@tiptap/extension-color": "^2.27.1",
|
"@tiptap/extension-color": "^2.10.3",
|
||||||
"@tiptap/extension-document": "^2.27.1",
|
"@tiptap/extension-document": "^2.10.3",
|
||||||
"@tiptap/extension-heading": "^2.27.1",
|
"@tiptap/extension-heading": "^2.10.3",
|
||||||
"@tiptap/extension-highlight": "^2.27.1",
|
"@tiptap/extension-highlight": "^2.10.3",
|
||||||
"@tiptap/extension-history": "^2.27.1",
|
"@tiptap/extension-history": "^2.10.3",
|
||||||
"@tiptap/extension-image": "^2.27.1",
|
"@tiptap/extension-image": "^2.10.3",
|
||||||
"@tiptap/extension-link": "^2.27.1",
|
"@tiptap/extension-link": "^2.10.3",
|
||||||
"@tiptap/extension-list-item": "^2.27.1",
|
"@tiptap/extension-list-item": "^2.10.3",
|
||||||
"@tiptap/extension-list-keymap": "^2.27.1",
|
"@tiptap/extension-list-keymap": "^2.10.3",
|
||||||
"@tiptap/extension-placeholder": "^2.27.1",
|
"@tiptap/extension-placeholder": "^2.10.3",
|
||||||
"@tiptap/extension-subscript": "^2.27.1",
|
"@tiptap/extension-subscript": "^2.10.3",
|
||||||
"@tiptap/extension-superscript": "^2.27.1",
|
"@tiptap/extension-superscript": "^2.10.3",
|
||||||
"@tiptap/extension-table": "^2.27.1",
|
"@tiptap/extension-table": "^2.10.3",
|
||||||
"@tiptap/extension-table-cell": "^2.27.1",
|
"@tiptap/extension-table-cell": "^2.10.3",
|
||||||
"@tiptap/extension-table-header": "^2.27.1",
|
"@tiptap/extension-table-header": "^2.10.3",
|
||||||
"@tiptap/extension-table-of-contents": "2.26.3",
|
"@tiptap/extension-table-row": "^2.10.3",
|
||||||
"@tiptap/extension-table-row": "^2.27.1",
|
"@tiptap/extension-task-item": "^2.10.3",
|
||||||
"@tiptap/extension-task-item": "^2.27.1",
|
"@tiptap/extension-task-list": "^2.10.3",
|
||||||
"@tiptap/extension-task-list": "^2.27.1",
|
"@tiptap/extension-text": "^2.10.3",
|
||||||
"@tiptap/extension-text": "^2.27.1",
|
"@tiptap/extension-text-align": "^2.10.3",
|
||||||
"@tiptap/extension-text-align": "^2.27.1",
|
"@tiptap/extension-text-style": "^2.10.3",
|
||||||
"@tiptap/extension-text-style": "^2.27.1",
|
"@tiptap/extension-typography": "^2.10.3",
|
||||||
"@tiptap/extension-typography": "^2.27.1",
|
"@tiptap/extension-underline": "^2.10.3",
|
||||||
"@tiptap/extension-underline": "^2.27.1",
|
"@tiptap/extension-youtube": "^2.10.3",
|
||||||
"@tiptap/extension-youtube": "^2.27.1",
|
"@tiptap/html": "^2.10.3",
|
||||||
"@tiptap/html": "^2.27.1",
|
"@tiptap/pm": "^2.10.3",
|
||||||
"@tiptap/pm": "^2.27.1",
|
"@tiptap/react": "^2.10.3",
|
||||||
"@tiptap/react": "^2.27.1",
|
"@tiptap/starter-kit": "^2.10.3",
|
||||||
"@tiptap/starter-kit": "^2.27.1",
|
"@tiptap/suggestion": "^2.10.3",
|
||||||
"@tiptap/suggestion": "^2.27.1",
|
|
||||||
"@types/qrcode": "^1.5.5",
|
"@types/qrcode": "^1.5.5",
|
||||||
"bytes": "^3.1.2",
|
"bytes": "^3.1.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
@@ -77,7 +76,6 @@
|
|||||||
"qrcode": "^1.5.4",
|
"qrcode": "^1.5.4",
|
||||||
"uuid": "^11.1.0",
|
"uuid": "^11.1.0",
|
||||||
"y-indexeddb": "^9.0.12",
|
"y-indexeddb": "^9.0.12",
|
||||||
"y-prosemirror": "1.3.7",
|
|
||||||
"yjs": "^13.6.27"
|
"yjs": "^13.6.27"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -100,8 +98,7 @@
|
|||||||
"react-arborist@3.4.0": "patches/react-arborist@3.4.0.patch"
|
"react-arborist@3.4.0": "patches/react-arborist@3.4.0.patch"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"jsdom": "25.0.1",
|
"jsdom": "25.0.1"
|
||||||
"y-prosemirror": "1.3.7"
|
|
||||||
},
|
},
|
||||||
"neverBuiltDependencies": []
|
"neverBuiltDependencies": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,3 @@ export * from "./lib/markdown";
|
|||||||
export * from "./lib/search-and-replace";
|
export * from "./lib/search-and-replace";
|
||||||
export * from "./lib/embed-provider";
|
export * from "./lib/embed-provider";
|
||||||
export * from "./lib/subpages";
|
export * from "./lib/subpages";
|
||||||
export * from "./lib/table-of-contents-node";
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export { TableOfContentsNode } from "./table-of-contents";
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import { Node } from "@tiptap/core";
|
|
||||||
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
||||||
|
|
||||||
export interface TableOfContentsNodeOptions {
|
|
||||||
HTMLAttributes: Record<string, any>;
|
|
||||||
view: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "@tiptap/core" {
|
|
||||||
interface Commands<ReturnType> {
|
|
||||||
tableOfContentsNode: {
|
|
||||||
insertTableOfContents: () => ReturnType;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TableOfContentsNode = Node.create<TableOfContentsNodeOptions>({
|
|
||||||
name: "tableOfContentsNode",
|
|
||||||
group: "block",
|
|
||||||
atom: true,
|
|
||||||
selectable: true,
|
|
||||||
draggable: true,
|
|
||||||
inline: false,
|
|
||||||
|
|
||||||
parseHTML() {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
tag: 'div[data-type="table-of-content"]',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
|
|
||||||
renderHTML({ HTMLAttributes }) {
|
|
||||||
return ["div", { ...HTMLAttributes, "data-type": "table-of-content" }];
|
|
||||||
},
|
|
||||||
|
|
||||||
addNodeView() {
|
|
||||||
return ReactNodeViewRenderer(this.options.view);
|
|
||||||
},
|
|
||||||
|
|
||||||
addCommands() {
|
|
||||||
return {
|
|
||||||
insertTableOfContents:
|
|
||||||
() =>
|
|
||||||
({ commands }) => {
|
|
||||||
return commands.insertContent({
|
|
||||||
type: this.name,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -5,7 +5,6 @@ import { CellSelection, TableMap } from "@tiptap/pm/tables";
|
|||||||
import { Node, ResolvedPos } from "@tiptap/pm/model";
|
import { Node, ResolvedPos } from "@tiptap/pm/model";
|
||||||
import Table from "@tiptap/extension-table";
|
import Table from "@tiptap/extension-table";
|
||||||
import { sanitizeUrl as braintreeSanitizeUrl } from "@braintree/sanitize-url";
|
import { sanitizeUrl as braintreeSanitizeUrl } from "@braintree/sanitize-url";
|
||||||
import { customAlphabet } from "nanoid";
|
|
||||||
|
|
||||||
export const isRectSelected = (rect: any) => (selection: CellSelection) => {
|
export const isRectSelected = (rect: any) => (selection: CellSelection) => {
|
||||||
const map = TableMap.get(selection.$anchorCell.node(-1));
|
const map = TableMap.get(selection.$anchorCell.node(-1));
|
||||||
@@ -384,12 +383,9 @@ export function icon(name: string) {
|
|||||||
|
|
||||||
export function sanitizeUrl(url: string | undefined): string {
|
export function sanitizeUrl(url: string | undefined): string {
|
||||||
if (!url) return "";
|
if (!url) return "";
|
||||||
|
|
||||||
const sanitized = braintreeSanitizeUrl(url);
|
const sanitized = braintreeSanitizeUrl(url);
|
||||||
|
|
||||||
// Return empty string instead of "about:blank"
|
// Return empty string instead of "about:blank"
|
||||||
return sanitized === "about:blank" ? "" : sanitized;
|
return sanitized === "about:blank" ? "" : sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
const alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
||||||
export const generateNodeId = customAlphabet(alphabet, 15);
|
|
||||||
|
|||||||
Generated
+402
-499
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user