mirror of
https://github.com/docmost/docmost.git
synced 2026-08-27 08:47:06 +08:00
* fix: close on click outside; smaller icon size * fix: make ALT more visible
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { Editor } from "@tiptap/core";
|
|
|
|
export function normalizeFileUrl(src: string): string {
|
|
if (src && src.startsWith("/files/")) {
|
|
return "/api" + src;
|
|
}
|
|
return src || "";
|
|
}
|
|
|
|
export function syncAltBadge(wrapper: HTMLElement, alt: unknown): void {
|
|
const existing = wrapper.querySelector<HTMLElement>(
|
|
":scope > .media-alt-badge",
|
|
);
|
|
|
|
if (typeof alt !== "string" || !alt.trim()) {
|
|
existing?.remove();
|
|
return;
|
|
}
|
|
|
|
const badge = existing ?? document.createElement("span");
|
|
badge.dataset.alt = alt;
|
|
|
|
if (!existing) {
|
|
badge.className = "media-alt-badge";
|
|
badge.textContent = "ALT";
|
|
badge.setAttribute("aria-hidden", "true");
|
|
wrapper.appendChild(badge);
|
|
}
|
|
}
|
|
|
|
export type UploadFn = (
|
|
file: File,
|
|
editor: Editor,
|
|
pos: number,
|
|
pageId: string,
|
|
// only applicable to file attachments
|
|
allowMedia?: boolean,
|
|
) => void;
|
|
|
|
export interface MediaUploadOptions {
|
|
validateFn?: (file: File, allowMedia?: boolean) => void;
|
|
onUpload: (file: File, pageId: string) => Promise<any>;
|
|
}
|