mirror of
https://github.com/docmost/docmost.git
synced 2025-11-16 08:41:08 +10:00
features and bug fixes (#322)
* fix page import title bug * fix youtube embed in markdown export * add link to rendered file html * fix: markdown callout import * update local generateJSON * feat: switch spaces from sidebar * remove unused package * feat: editor date menu command * fix date description * update default locale code * feat: add more code highlight languages
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
.spaceName {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: var(--mantine-spacing-sm);
|
||||
color: light-dark(var(--mantine-color-black), var(--mantine-color-dark-0));
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
import { UnstyledButton, Group, Text } from "@mantine/core";
|
||||
import classes from "./space-name.module.css";
|
||||
|
||||
interface SpaceNameProps {
|
||||
spaceName: string;
|
||||
}
|
||||
export function SpaceName({ spaceName }: SpaceNameProps) {
|
||||
return (
|
||||
<UnstyledButton className={classes.spaceName}>
|
||||
<Group>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Text size="md" fw={500} lineClamp={1}>
|
||||
{spaceName}
|
||||
</Text>
|
||||
</div>
|
||||
</Group>
|
||||
</UnstyledButton>
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useDebouncedValue } from '@mantine/hooks';
|
||||
import { Avatar, Group, Select, SelectProps, Text } from '@mantine/core';
|
||||
import { useGetSpacesQuery } from '@/features/space/queries/space-query.ts';
|
||||
import { ISpace } from '../../types/space.types';
|
||||
|
||||
interface SpaceSelectProps {
|
||||
onChange: (value: string) => void;
|
||||
value?: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
const renderSelectOption: SelectProps['renderOption'] = ({ option }) => (
|
||||
<Group gap="sm">
|
||||
<Avatar color="initials" variant="filled" name={option.label} size={20} />
|
||||
<div>
|
||||
<Text size="sm">{option.label}</Text>
|
||||
</div>
|
||||
</Group>
|
||||
);
|
||||
|
||||
export function SpaceSelect({ onChange, label, value }: SpaceSelectProps) {
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const [debouncedQuery] = useDebouncedValue(searchValue, 500);
|
||||
const { data: spaces, isLoading } = useGetSpacesQuery({
|
||||
query: debouncedQuery,
|
||||
limit: 50,
|
||||
});
|
||||
const [data, setData] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (spaces) {
|
||||
const spaceData = spaces?.items
|
||||
.filter((space: ISpace) => space.slug !== value)
|
||||
.map((space: ISpace) => {
|
||||
return {
|
||||
label: space.name,
|
||||
value: space.slug,
|
||||
};
|
||||
});
|
||||
|
||||
const filteredSpaceData = spaceData.filter(
|
||||
(user) =>
|
||||
!data.find((existingUser) => existingUser.value === user.value)
|
||||
);
|
||||
setData((prevData) => [...prevData, ...filteredSpaceData]);
|
||||
}
|
||||
}, [spaces]);
|
||||
|
||||
return (
|
||||
<Select
|
||||
data={data}
|
||||
renderOption={renderSelectOption}
|
||||
maxDropdownHeight={300}
|
||||
//label={label || 'Select space'}
|
||||
placeholder="Search for spaces"
|
||||
searchable
|
||||
searchValue={searchValue}
|
||||
onSearchChange={setSearchValue}
|
||||
clearable
|
||||
variant="filled"
|
||||
onChange={onChange}
|
||||
nothingFoundMessage="No space found"
|
||||
limit={50}
|
||||
checkIconPosition="right"
|
||||
comboboxProps={{ width: 300, withinPortal: false }}
|
||||
dropdownOpened
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -5,8 +5,8 @@ import {
|
||||
Text,
|
||||
Tooltip,
|
||||
UnstyledButton,
|
||||
} from "@mantine/core";
|
||||
import { spotlight } from "@mantine/spotlight";
|
||||
} from '@mantine/core';
|
||||
import { spotlight } from '@mantine/spotlight';
|
||||
import {
|
||||
IconArrowDown,
|
||||
IconDots,
|
||||
@ -14,27 +14,27 @@ import {
|
||||
IconPlus,
|
||||
IconSearch,
|
||||
IconSettings,
|
||||
} from "@tabler/icons-react";
|
||||
} from '@tabler/icons-react';
|
||||
|
||||
import classes from "./space-sidebar.module.css";
|
||||
import React, { useMemo } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { SearchSpotlight } from "@/features/search/search-spotlight.tsx";
|
||||
import { treeApiAtom } from "@/features/page/tree/atoms/tree-api-atom.ts";
|
||||
import { Link, useLocation, useParams } from "react-router-dom";
|
||||
import clsx from "clsx";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import SpaceSettingsModal from "@/features/space/components/settings-modal.tsx";
|
||||
import { useGetSpaceBySlugQuery } from "@/features/space/queries/space-query.ts";
|
||||
import { SpaceName } from "@/features/space/components/sidebar/space-name.tsx";
|
||||
import { getSpaceUrl } from "@/lib/config.ts";
|
||||
import SpaceTree from "@/features/page/tree/components/space-tree.tsx";
|
||||
import { useSpaceAbility } from "@/features/space/permissions/use-space-ability.ts";
|
||||
import classes from './space-sidebar.module.css';
|
||||
import React, { useMemo } from 'react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { SearchSpotlight } from '@/features/search/search-spotlight.tsx';
|
||||
import { treeApiAtom } from '@/features/page/tree/atoms/tree-api-atom.ts';
|
||||
import { Link, useLocation, useParams } from 'react-router-dom';
|
||||
import clsx from 'clsx';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
import SpaceSettingsModal from '@/features/space/components/settings-modal.tsx';
|
||||
import { useGetSpaceBySlugQuery } from '@/features/space/queries/space-query.ts';
|
||||
import { getSpaceUrl } from '@/lib/config.ts';
|
||||
import SpaceTree from '@/features/page/tree/components/space-tree.tsx';
|
||||
import { useSpaceAbility } from '@/features/space/permissions/use-space-ability.ts';
|
||||
import {
|
||||
SpaceCaslAction,
|
||||
SpaceCaslSubject,
|
||||
} from "@/features/space/permissions/permissions.type.ts";
|
||||
import PageImportModal from "@/features/page/components/page-import-modal.tsx";
|
||||
} from '@/features/space/permissions/permissions.type.ts';
|
||||
import PageImportModal from '@/features/page/components/page-import-modal.tsx';
|
||||
import { SwitchSpace } from './switch-space';
|
||||
|
||||
export function SpaceSidebar() {
|
||||
const [tree] = useAtom(treeApiAtom);
|
||||
@ -52,7 +52,7 @@ export function SpaceSidebar() {
|
||||
}
|
||||
|
||||
function handleCreatePage() {
|
||||
tree?.create({ parentId: null, type: "internal", index: 0 });
|
||||
tree?.create({ parentId: null, type: 'internal', index: 0 });
|
||||
}
|
||||
|
||||
return (
|
||||
@ -61,11 +61,12 @@ export function SpaceSidebar() {
|
||||
<div
|
||||
className={classes.section}
|
||||
style={{
|
||||
border: "none",
|
||||
marginBottom: "0",
|
||||
border: 'none',
|
||||
marginTop: 2,
|
||||
marginBottom: 3,
|
||||
}}
|
||||
>
|
||||
<SpaceName spaceName={space?.name} />
|
||||
<SwitchSpace spaceName={space?.name} spaceSlug={space?.slug} />
|
||||
</div>
|
||||
|
||||
<div className={classes.section}>
|
||||
@ -77,7 +78,7 @@ export function SpaceSidebar() {
|
||||
classes.menu,
|
||||
location.pathname.toLowerCase() === getSpaceUrl(spaceSlug)
|
||||
? classes.activeButton
|
||||
: "",
|
||||
: ''
|
||||
)}
|
||||
>
|
||||
<div className={classes.menuItemInner}>
|
||||
@ -114,7 +115,7 @@ export function SpaceSidebar() {
|
||||
|
||||
{spaceAbility.can(
|
||||
SpaceCaslAction.Manage,
|
||||
SpaceCaslSubject.Page,
|
||||
SpaceCaslSubject.Page
|
||||
) && (
|
||||
<UnstyledButton
|
||||
className={classes.menu}
|
||||
@ -141,7 +142,7 @@ export function SpaceSidebar() {
|
||||
|
||||
{spaceAbility.can(
|
||||
SpaceCaslAction.Manage,
|
||||
SpaceCaslSubject.Page,
|
||||
SpaceCaslSubject.Page
|
||||
) && (
|
||||
<Group gap="xs">
|
||||
<SpaceMenu spaceId={space.id} onSpaceSettings={openSettings} />
|
||||
@ -165,7 +166,7 @@ export function SpaceSidebar() {
|
||||
spaceId={space.id}
|
||||
readOnly={spaceAbility.cannot(
|
||||
SpaceCaslAction.Manage,
|
||||
SpaceCaslSubject.Page,
|
||||
SpaceCaslSubject.Page
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
.spaceName {
|
||||
width: 100%;
|
||||
padding: var(--mantine-spacing-sm);
|
||||
color: light-dark(var(--mantine-color-dark-4), var(--mantine-color-dark-0));
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
import classes from './switch-space.module.css';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { SpaceSelect } from './space-select';
|
||||
import { getSpaceUrl } from '@/lib/config';
|
||||
import { Avatar, Button, Popover, Text } from '@mantine/core';
|
||||
import { IconChevronDown } from '@tabler/icons-react';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
|
||||
interface SwitchSpaceProps {
|
||||
spaceName: string;
|
||||
spaceSlug: string;
|
||||
}
|
||||
|
||||
export function SwitchSpace({ spaceName, spaceSlug }: SwitchSpaceProps) {
|
||||
const [opened, { close, open, toggle }] = useDisclosure(false);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSelect = (value: string) => {
|
||||
if (value) {
|
||||
navigate(getSpaceUrl(value));
|
||||
close();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover
|
||||
width={300}
|
||||
position="bottom"
|
||||
withArrow
|
||||
shadow="md"
|
||||
opened={opened}
|
||||
>
|
||||
<Popover.Target>
|
||||
<Button
|
||||
variant="subtle"
|
||||
fullWidth
|
||||
justify="space-between"
|
||||
rightSection={<IconChevronDown size={18} />}
|
||||
color="gray"
|
||||
onClick={toggle}
|
||||
>
|
||||
<Avatar
|
||||
size={20}
|
||||
color="initials"
|
||||
variant="filled"
|
||||
name={spaceName}
|
||||
/>
|
||||
<Text className={classes.spaceName} size="md" fw={500} lineClamp={1}>
|
||||
{spaceName}
|
||||
</Text>
|
||||
</Button>
|
||||
</Popover.Target>
|
||||
<Popover.Dropdown>
|
||||
<SpaceSelect
|
||||
label={spaceName}
|
||||
value={spaceSlug}
|
||||
onChange={handleSelect}
|
||||
/>
|
||||
</Popover.Dropdown>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user