-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: grnd-alt <[email protected]>
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { convertToExcalidrawElements } from "@excalidraw/excalidraw"; | ||
Check failure on line 1 in src/files/files.ts GitHub Actions / NPM lint
|
||
import type { ExcalidrawImperativeAPI } from "@excalidraw/excalidraw/types/types" | ||
|
||
function addCustomFileElement(excalidrawApi: ExcalidrawImperativeAPI, link: string) { | ||
let elements = excalidrawApi.getSceneElementsIncludingDeleted().slice(); | ||
Check failure on line 5 in src/files/files.ts GitHub Actions / NPM lint
|
||
const newElements = convertToExcalidrawElements([{ | ||
text: link, | ||
type: "text", | ||
fontSize: 16, | ||
textAlign: "left", | ||
fontFamily: 1, | ||
x: 0, | ||
y: 0, | ||
}]) | ||
elements.push(newElements[0]) | ||
excalidrawApi.updateScene({ elements }) | ||
} | ||
|
||
// TODO: Implement uploading to nextcloud | ||
function UploadFileToNextcloud(file: File) { | ||
return | ||
} | ||
|
||
function filesEventListener(ev: Event, excalidrawApi: ExcalidrawImperativeAPI) { | ||
if (ev instanceof DragEvent) { | ||
UploadFileToNextcloud(ev.dataTransfer?.files[0]!) | ||
const types = ["image/webp"] | ||
if (!types.includes(ev.dataTransfer?.files[0].type || "")) { | ||
addCustomFileElement(excalidrawApi, ev.dataTransfer?.files[0].name || "no file name") | ||
ev.stopImmediatePropagation() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
Check warning on line 35 in src/files/files.ts GitHub Actions / NPM lint
|
||
* adds drop eventlistener to excalidraw | ||
* uploads file to nextcloud server, to be shared with all users | ||
* if filetype not supported by excalidraw inserts link to file | ||
*/ | ||
export function registerFilesHandler(excalidrawApi: ExcalidrawImperativeAPI) { | ||
const containerRef = document.getElementsByClassName("excalidraw-container")[0] | ||
if (containerRef) { | ||
containerRef.addEventListener('drop', (ev) => filesEventListener(ev, excalidrawApi)) | ||
} | ||
} |