Skip to content

Commit

Permalink
Merge pull request #54 from GBSL-Informatik/feature/excali-files
Browse files Browse the repository at this point in the history
Feature/excali-files
  • Loading branch information
lebalz authored Nov 26, 2024
2 parents f1dde9f + 375746b commit 922fe20
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 48 deletions.
6 changes: 5 additions & 1 deletion docs/Komponentengalerie/files-and-folders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import Directory from '@tdev-components/documents/FileSystem/Directory';

## Installation

:::info[Code-Ordner kopieren]
::::info[Code-Ordner kopieren]
- `src/models/documents/FileSystem`
- `src/components/documents/FileSystem`

:::warning[Abhängigkeiten]
Standardmässig werden alle verfügbaren Dateitypen unterstützt. Ist ein Dokumententyp (bspw. `excalidoc`) nicht verfügbar, muss dieser entfernt werden.
:::
::::

:::info[Models]

Expand Down
6 changes: 5 additions & 1 deletion src/components/PermissionsPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Popup from 'reactjs-popup';
import styles from './styles.module.scss';
import Button from '@tdev-components/shared/Button';
import { mdiShieldLockOutline } from '@mdi/js';
import DocumentRoot from '@tdev-models/DocumentRoot';
import { observer } from 'mobx-react-lite';
import { Access } from '@tdev-api/document';
import { useStore } from '@tdev-hooks/useStore';
Expand All @@ -15,6 +14,7 @@ import DefinitionList from '../DefinitionList';
import { action } from 'mobx';
import UserPermission from '@tdev-components/PermissionsPanel/UserPermission';
import { PopupPosition } from 'reactjs-popup/dist/types';
import useIsMobileView from '@tdev-hooks/useIsMobileView';

interface Props {
documentRootId: string;
Expand All @@ -25,6 +25,7 @@ const PermissionsPanel = observer(({ documentRootId, position }: Props) => {
const userStore = useStore('userStore');
const documentRootStore = useStore('documentRootStore');
const permissionStore = useStore('permissionStore');
const isMobileView = useIsMobileView(470);
const documentRoot = documentRootStore.find(documentRootId);
const { viewedUser } = userStore;

Expand Down Expand Up @@ -67,8 +68,11 @@ const PermissionsPanel = observer(({ documentRootId, position }: Props) => {
}
on="click"
closeOnDocumentClick
overlayStyle={{ background: isMobileView ? 'rgba(0,0,0,0.5)' : undefined }}
closeOnEscape
position={position}
keepTooltipInside=".markdown"
modal={isMobileView}
onOpen={action(() => {
permissionStore.loadPermissions(documentRoot);
})}
Expand Down
3 changes: 2 additions & 1 deletion src/components/PermissionsPanel/styles.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.wrapper {
max-height: 90vh;
max-height: 85vh;
max-width: 95vw;
min-width: 20em;
padding: 1em;
overflow: auto;
--ifm-global-shadow-lw: var(--ifm-global-shadow-tl);
Expand Down
6 changes: 1 addition & 5 deletions src/components/Rooms/TextMessages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ const TextMessages = observer((props: Props): JSX.Element => {
<div className={clsx(styles.wrapper)}>
<div className={clsx(styles.rooms)}>
<h1 className={clsx(styles.name)}>
{dynamicDocumentRoot.name}{' '}
<PermissionsPanel
documentRootId={documentRoot.id}
position={['top right', 'bottom right']}
/>
{dynamicDocumentRoot.name} <PermissionsPanel documentRootId={documentRoot.id} />
</h1>
<Conversation group={documentRoot} />
<NewMessage group={documentRoot} />
Expand Down
5 changes: 1 addition & 4 deletions src/components/Rooms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ const RoomComponent = observer((props: Props): JSX.Element => {
return (
<>
<NoAccess header={dynamicRoot.name}>
<PermissionsPanel
documentRootId={roomProps.id}
position={['top right', 'bottom right']}
/>
<PermissionsPanel documentRootId={roomProps.id} />
</NoAccess>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const DynamicDocumentRoot = observer((props: Props) => {
/>
</>
)}
<PermissionsPanel documentRootId={docRoot.id} position={['bottom right', 'top right']} />
<PermissionsPanel documentRootId={docRoot.id} />
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/documents/DynamicDocumentRoots/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DynamicDocumentRoots = observer((props: Props) => {
<div className={clsx('card', styles.docRoots)}>
<div className={clsx(styles.header, 'card__header')}>
<h3>{props.name || 'Gruppe'}</h3>
<PermissionsPanel documentRootId={props.id} position={['top right', 'bottom right']} />
<PermissionsPanel documentRootId={props.id} />
</div>
<div className={clsx(styles.body, 'card__body')}>
<div className={clsx(styles.actions)}>
Expand Down
32 changes: 27 additions & 5 deletions src/components/documents/Excalidoc/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import { useColorMode } from '@docusaurus/theme-common';
import type { default as ExcalidrawLib } from '@excalidraw/excalidraw';
import _ from 'lodash';
import { useFirstRealMainDocument } from '@tdev-hooks/useFirstRealMainDocument';
import { useDocument } from '@tdev-hooks/useDocument';
import { DocumentType } from '@tdev-api/document';

export interface Props extends MetaInit {
Lib: typeof ExcalidrawLib;
id: string;
meta: ModelMeta;
documentId: string;
libraryItems?: LibraryItems;
allowImageInsertion?: boolean;
readonly?: boolean;
}

const Editor = observer((props: Props) => {
const { Lib, meta } = props;
const excalidoc = useFirstRealMainDocument(props.id, meta);
const { Lib, documentId } = props;
const excalidoc = useDocument<DocumentType.Excalidoc>(documentId);
const renderedSceneVersion = React.useRef(0);
const initialized = React.useRef<boolean>(false);
const apiSceneVersion = React.useRef(0);
const [excalidrawAPI, setExcalidrawAPI] = React.useState<ExcalidrawImperativeAPI>();
const { colorMode } = useColorMode();

React.useEffect(() => {
if (excalidrawAPI && excalidoc && !initialized.current) {
excalidrawAPI.scrollToContent(excalidoc.elements, { fitToViewport: true });
Expand Down Expand Up @@ -79,6 +81,26 @@ const Editor = observer((props: Props) => {
};
}
}, [excalidrawAPI, excalidoc]);

/**
* ensure that excalidraw has a correct offset and scroll position
* for cursors.
* Reading the docs, this should not be needed: https://docs.excalidraw.com/docs/@excalidraw/excalidraw/api/props/excalidraw-api#refresh
* But somehow, this bug's for the viewMode...
*/
React.useEffect(() => {
const onscroll = _.debounce(() => {
if (excalidrawAPI) {
excalidrawAPI.refresh();
}
}, 50);
document.addEventListener('scroll', onscroll);
return () => {
onscroll.cancel();
document.removeEventListener('scroll', onscroll);
};
}, [excalidrawAPI]);

if (!excalidoc || !Lib) {
return null;
}
Expand All @@ -94,8 +116,8 @@ const Editor = observer((props: Props) => {
scrollToContent: true,
libraryItems: props.libraryItems
}}
excalidrawAPI={(api) => setExcalidrawAPI(api)}
objectsSnapModeEnabled
excalidrawAPI={(api) => setExcalidrawAPI(api)}
langCode="de-DE"
theme={colorMode === 'dark' ? 'dark' : 'light'}
UIOptions={{
Expand Down
12 changes: 4 additions & 8 deletions src/components/documents/Excalidoc/Preview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import React from 'react';
import { observer } from 'mobx-react-lite';
import styles from './styles.module.scss';
import { ModelMeta } from '@site/src/models/documents/Excalidoc';
import _ from 'lodash';
import clsx from 'clsx';
import { useFirstRealMainDocument } from '@tdev-hooks/useFirstRealMainDocument';
import Image from './Image';
import { useDocument } from '@tdev-hooks/useDocument';
import { DocumentType } from '@tdev-api/document';

export interface Props {
id: string;
meta: ModelMeta;
documentId: string;
}

const Preview = observer((props: Props) => {
const { meta } = props;
const excalidoc = useFirstRealMainDocument(props.id, meta);
const excalidoc = useDocument<DocumentType.Excalidoc>(props.documentId);
if (!excalidoc) {
return null;
}
Expand Down
Loading

0 comments on commit 922fe20

Please sign in to comment.