import type React from 'react' import { useCallback, useEffect, useRef } from 'react' import { cn } from '@/lib/utils' import { translate, type AppLocale } from '../../lib/i18n' import { dispatchEditorFindAvailability } from '../../utils/editorFindEvents' import { DiffView } from '../DiffView' import { BreadcrumbBar } from '../BreadcrumbBar' import { ArchivedNoteBanner } from '../ArchivedNoteBanner' import { ConflictNoteBanner } from '../ConflictNoteBanner' import { RawEditorView } from '../RawEditorView' import { SingleEditorView } from '../SingleEditorView' import type { useEditorContentModel } from './useEditorContentModel' type EditorContentModel = ReturnType type BreadcrumbActions = Pick< EditorContentModel, | 'diffMode' | 'diffLoading' | 'onToggleDiff' | 'effectiveRawMode' | 'onToggleRaw' | 'forceRawMode' | 'showAIChat' | 'onToggleAIChat' | 'inspectorCollapsed' | 'onToggleInspector' | 'showDiffToggle' | 'onToggleFavorite' | 'onToggleOrganized' | 'onRevealFile' | 'onCopyFilePath' | 'onDeleteNote' | 'onArchiveNote' | 'onUnarchiveNote' | 'onRenameFilename' | 'noteLayout' | 'onToggleNoteLayout' > function EditorLoadingSkeleton() { return (
) } function DiffModeView({ diffContent, locale = 'en', onToggleDiff }: { diffContent: string | null; locale?: AppLocale; onToggleDiff: () => void }) { const label = translate(locale, 'editor.toolbar.rawReturn') return (
) } function RawModeEditorSection({ activeTab, entries, findRequest, rawMode, rawModeContent, onRawContentChange, onSave, rawLatestContentRef, vaultPath, locale, }: Pick< EditorContentModel, 'activeTab' | 'entries' | 'findRequest' | 'onRawContentChange' | 'onSave' | 'rawLatestContentRef' | 'rawModeContent' | 'vaultPath' > & { rawMode: boolean locale?: AppLocale }) { if (!rawMode || !activeTab) return null return (
{})} onSave={onSave ?? (() => {})} latestContentRef={rawLatestContentRef} vaultPath={vaultPath} locale={locale} />
) } function bindPath(cb: ((path: string) => void) | undefined, path: string) { return cb ? () => cb(path) : undefined } function ActiveTabBreadcrumb({ activeTab, barRef, wordCount, path, actions, locale, }: { activeTab: NonNullable barRef: React.RefObject wordCount: number path: string actions: BreadcrumbActions locale?: AppLocale }) { return ( ) } function EditorChrome({ isArchived, onUnarchiveNote, path, isConflicted, onKeepMine, onKeepTheirs, diffMode, diffContent, onToggleDiff, locale, }: Pick< EditorContentModel, 'isArchived' | 'onUnarchiveNote' | 'path' | 'isConflicted' | 'onKeepMine' | 'onKeepTheirs' | 'diffMode' | 'diffContent' | 'onToggleDiff' | 'locale' >) { return ( <> {isArchived && onUnarchiveNote && ( onUnarchiveNote(path)} locale={locale} /> )} {isConflicted && ( onKeepMine?.(path)} onKeepTheirs={() => onKeepTheirs?.(path)} locale={locale} /> )} {diffMode && } ) } function EditorCanvas({ showEditor, cssVars, editor, entries, onNavigateWikilink, onEditorChange, isDeletedPreview, vaultPath, }: Pick< EditorContentModel, | 'showEditor' | 'cssVars' | 'editor' | 'entries' | 'onNavigateWikilink' | 'onEditorChange' | 'isDeletedPreview' | 'vaultPath' >) { if (!showEditor) return null return (
) } function EditorFindScope({ children, className, style, }: { children: React.ReactNode className?: string style?: React.CSSProperties }) { const scopeRef = useRef(null) const syncAvailability = useCallback(() => { const activeElement = document.activeElement const enabled = activeElement instanceof Node && scopeRef.current?.contains(activeElement) === true dispatchEditorFindAvailability(enabled) }, []) useEffect(() => () => dispatchEditorFindAvailability(false), []) return (
dispatchEditorFindAvailability(true)} onBlurCapture={() => requestAnimationFrame(syncAvailability)} style={style} > {children}
) } export function EditorContentLayout(model: EditorContentModel) { const { activeTab, isLoadingNewTab, entries, editor, diffMode, diffContent, onToggleDiff, effectiveRawMode, onRawContentChange, onSave, showEditor, isArchived, onUnarchiveNote, path, isConflicted, onKeepMine, onKeepTheirs, breadcrumbBarRef, wordCount, vaultPath, cssVars, onNavigateWikilink, onEditorChange, isDeletedPreview, rawLatestContentRef, rawModeContent, noteLayout, findRequest, locale, } = model const rootClassName = cn( 'flex flex-1 flex-col min-w-0 min-h-0', noteLayout === 'left' ? 'editor-content-layout--left' : 'editor-content-layout--centered', ) if (!activeTab) { return (
{isLoadingNewTab && showEditor && }
) } return (
{isLoadingNewTab && showEditor && }
) }