mirror of https://github.com/usememos/memos
refactor: consolidate and update type definitions across MemoEditor components
parent
40585607f4
commit
792d58b74d
@ -1,39 +0,0 @@
|
||||
import { useState } from "react";
|
||||
import type { LocalFile } from "@/components/memo-metadata";
|
||||
import { useBlobUrls } from "./useBlobUrls";
|
||||
|
||||
export function useLocalFileManager() {
|
||||
const [localFiles, setLocalFiles] = useState<LocalFile[]>([]);
|
||||
const { createBlobUrl, revokeBlobUrl } = useBlobUrls();
|
||||
|
||||
const addFiles = (files: FileList | File[]): void => {
|
||||
const fileArray = Array.from(files);
|
||||
const newLocalFiles: LocalFile[] = fileArray.map((file) => ({
|
||||
file,
|
||||
previewUrl: createBlobUrl(file),
|
||||
}));
|
||||
setLocalFiles((prev) => [...prev, ...newLocalFiles]);
|
||||
};
|
||||
|
||||
const removeFile = (previewUrl: string): void => {
|
||||
setLocalFiles((prev) => {
|
||||
const toRemove = prev.find((f) => f.previewUrl === previewUrl);
|
||||
if (toRemove) {
|
||||
revokeBlobUrl(toRemove.previewUrl);
|
||||
}
|
||||
return prev.filter((f) => f.previewUrl !== previewUrl);
|
||||
});
|
||||
};
|
||||
|
||||
const clearFiles = (): void => {
|
||||
localFiles.forEach(({ previewUrl }) => revokeBlobUrl(previewUrl));
|
||||
setLocalFiles([]);
|
||||
};
|
||||
|
||||
return {
|
||||
localFiles,
|
||||
addFiles,
|
||||
removeFile,
|
||||
clearFiles,
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
import type { LatLng } from "leaflet";
|
||||
import type { Location, Memo, Visibility } from "@/types/proto/api/v1/memo_service_pb";
|
||||
import type { EditorRefActions } from "../Editor";
|
||||
import type { Command } from "../Editor/commands";
|
||||
import type { LocationState } from "./insert-menu";
|
||||
|
||||
export interface MemoEditorProps {
|
||||
className?: string;
|
||||
cacheKey?: string;
|
||||
placeholder?: string;
|
||||
memoName?: string;
|
||||
parentMemoName?: string;
|
||||
autoFocus?: boolean;
|
||||
onConfirm?: (memoName: string) => void;
|
||||
onCancel?: () => void;
|
||||
}
|
||||
|
||||
export interface EditorContentProps {
|
||||
placeholder?: string;
|
||||
autoFocus?: boolean;
|
||||
}
|
||||
|
||||
export interface EditorToolbarProps {
|
||||
onSave: () => void;
|
||||
onCancel?: () => void;
|
||||
memoName?: string;
|
||||
}
|
||||
|
||||
export interface EditorMetadataProps {}
|
||||
|
||||
export interface FocusModeOverlayProps {
|
||||
isActive: boolean;
|
||||
onToggle: () => void;
|
||||
}
|
||||
|
||||
export interface FocusModeExitButtonProps {
|
||||
isActive: boolean;
|
||||
onToggle: () => void;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export interface LinkMemoDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
searchText: string;
|
||||
onSearchChange: (text: string) => void;
|
||||
filteredMemos: Memo[];
|
||||
isFetching: boolean;
|
||||
onSelectMemo: (memo: Memo) => void;
|
||||
}
|
||||
|
||||
export interface LocationDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
state: LocationState;
|
||||
locationInitialized: boolean;
|
||||
onPositionChange: (position: LatLng) => void;
|
||||
onUpdateCoordinate: (type: "lat" | "lng", value: string) => void;
|
||||
onPlaceholderChange: (placeholder: string) => void;
|
||||
onCancel: () => void;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
export interface InsertMenuProps {
|
||||
isUploading?: boolean;
|
||||
location?: Location;
|
||||
onLocationChange: (location?: Location) => void;
|
||||
onToggleFocusMode?: () => void;
|
||||
memoName?: string;
|
||||
}
|
||||
|
||||
export interface TagSuggestionsProps {
|
||||
editorRef: React.RefObject<HTMLTextAreaElement>;
|
||||
editorActions: React.ForwardedRef<EditorRefActions>;
|
||||
}
|
||||
|
||||
export interface SlashCommandsProps {
|
||||
editorRef: React.RefObject<HTMLTextAreaElement>;
|
||||
editorActions: React.ForwardedRef<EditorRefActions>;
|
||||
commands: Command[];
|
||||
}
|
||||
|
||||
export interface EditorProps {
|
||||
className: string;
|
||||
initialContent: string;
|
||||
placeholder: string;
|
||||
onContentChange: (content: string) => void;
|
||||
onPaste: (event: React.ClipboardEvent) => void;
|
||||
isFocusMode?: boolean;
|
||||
isInIME?: boolean;
|
||||
onCompositionStart?: () => void;
|
||||
onCompositionEnd?: () => void;
|
||||
}
|
||||
|
||||
export interface VisibilitySelectorProps {
|
||||
value: Visibility;
|
||||
onChange: (visibility: Visibility) => void;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
@ -1,3 +1,19 @@
|
||||
// MemoEditor type exports
|
||||
|
||||
export type {
|
||||
EditorContentProps,
|
||||
EditorMetadataProps,
|
||||
EditorProps,
|
||||
EditorToolbarProps,
|
||||
FocusModeExitButtonProps,
|
||||
FocusModeOverlayProps,
|
||||
InsertMenuProps,
|
||||
LinkMemoDialogProps,
|
||||
LocationDialogProps,
|
||||
MemoEditorProps,
|
||||
SlashCommandsProps,
|
||||
TagSuggestionsProps,
|
||||
VisibilitySelectorProps,
|
||||
} from "./components";
|
||||
export { MemoEditorContext, type MemoEditorContextValue } from "./context";
|
||||
export type { LocationState } from "./insert-menu";
|
||||
|
||||
Loading…
Reference in New Issue