Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112// src/plugin/files/file.tsimport { TAbstractFile } from './abstract-file'import type { TFolder } from './folder'
/** * File statistics. */export interface FileStats { /** Creation time in milliseconds */ ctime: number /** Modification time in milliseconds */ mtime: number /** File size in bytes */ size: number}
/** * Compute basename (name without extension) from a filename. * @internal */function computeBasename(name: string): string { const dotIndex = name.lastIndexOf('.') // No dot, or dot at start (dotfile), means no extension if (dotIndex <= 0) { return name } return name.slice(0, dotIndex)}
/** * Compute extension (without dot) from a filename. * @internal */function computeExtension(name: string): string { const dotIndex = name.lastIndexOf('.') // No dot, or dot at start (dotfile), means no extension if (dotIndex <= 0) { return '' } return name.slice(dotIndex + 1)}
/** * Represents a file in the vault. */export class TFile extends TAbstractFile { /** * File statistics. Mutable for update operations. * @public * @since 0.9.7 */ stat: FileStats
/** * File name without extension (e.g., "daily" for "daily.md"). * @public * @since 0.9.7 */ basename: string
/** * File extension without dot (e.g., "md"). * @public * @since 0.9.7 */ extension: string
/** * @internal * Constructor is not part of the public API. Use Vault methods to create files. */ protected constructor(name: string, parent: TFolder | null, stat: FileStats) { super(name, parent) this.stat = stat this.basename = computeBasename(name) this.extension = computeExtension(name) }}
/** * Update TFile's basename and extension when it is renamed. * Called by Vault after rename operations. * @internal - Not exported from the 'obsidian' module. */export function updateFileNameParts(file: TFile): void { file.basename = computeBasename(file.name) file.extension = computeExtension(file.name)}
/** * Internal factory function to create TFile instances. * This is NOT part of the public Obsidian API. Use Vault.create() for plugin code. * * Exists to allow internal Reams code (services, tests) to create TFile instances * while keeping the constructor protected to match Obsidian's public API contract. * * @internal - Not exported from the 'obsidian' module. */export function createTFile(name: string, parent: TFolder | null, stat: FileStats): TFile { // Use Object.create + manual property assignment to bypass protected constructor // This is an internal implementation detail. const file = Object.create(TFile.prototype) as TFile // Call the base class initialization logic ;(file as any).name = name ;(file as any).parent = parent ;(file as any).path = parent && !parent.isRoot() ? `${parent.path}/${name}` : name file.stat = stat file.basename = computeBasename(name) file.extension = computeExtension(name) return file}