/** * @file * * Mock of Obsidian's `WorkspaceItem`, the abstract base of every node in the workspace layout tree. */ import type { WorkspaceContainer as WorkspaceContainerOriginal, WorkspaceItem as WorkspaceItemOriginal, WorkspaceParent as WorkspaceParentOriginal } from 'obsidian'; import type { SerializedWorkspaceItem } from '../internal/types.mjs'; import type { Workspace } from './Workspace.mjs'; import { Events } from './Events.mjs'; /** * Mock of Obsidian's `WorkspaceItem`, the base of leaves, splits, tabs and the other layout nodes. * * Items form a real layout tree through {@link WorkspaceItem.parent} and `WorkspaceParent.children`, so * {@link WorkspaceItem.getRoot} and {@link WorkspaceItem.getContainer} walk up it the way Obsidian does. */ export declare abstract class WorkspaceItem extends Events { /** * The item's own element. * * The mock does NOT build the layout's DOM tree: each item gets a detached element of its own, so a child's * element is not inside its parent's, and the layout is read through {@link WorkspaceItem.parent} and * `WorkspaceParent.children` instead. The one containment it does maintain is a leaf's view — `WorkspaceLeaf.open` * appends the view's element here and detaches it again when the view closes. */ containerEl: HTMLElement; /** * The item's share of its parent split, as a flex-grow value, or `null` when it takes its natural share. The * workspace sets it when it creates, splits or promotes an item; nothing is rendered from it. */ dimension: null | number; /** * The item id, which a serialized layout records and `Workspace.getLeafById` looks a leaf up by: the one given at * construction, or the next value of a module-wide counter. */ id: string; /** * The direct parent of the item. An item with no parent holds an empty strict proxy instead, which throws on any * member access; {@link WorkspaceItem.setParent} and `WorkspaceParent.insertChild` replace it. */ parent: WorkspaceParentOriginal; /** * The item's kind, the `type` its serialized form carries: `split`, `tabs`, `leaf`, `floating`, `window` or * `mobile-drawer`. */ abstract type: string; /** * The workspace the item belongs to, which subclasses reach for `onLayoutChange` and the layout requests. It is * optional because a test can build a bare item with no workspace at all; every item the workspace itself creates * has one. */ protected readonly layoutWorkspace: undefined | Workspace; /** * Creates a workspace item. * * @param workspace - The workspace the item belongs to; {@link WorkspaceItem.getContainer} falls back to its root * split. * @param id - The item id; a unique numeric id is generated when omitted. */ protected constructor(workspace?: Workspace, id?: string); /** * Mock-only: views a value typed as Obsidian's `WorkspaceItem` as this mock. The numbered subclass variant of * `fromOriginalType__`. * * @param value - The value typed as the original `WorkspaceItem`. * @returns The same object, typed as the mock. */ static fromOriginalType2__(value: WorkspaceItemOriginal): WorkspaceItem; /** * Mock-only: views this mock as Obsidian's `WorkspaceItem` type. The numbered subclass variant of * `asOriginalType__`. * * @returns The same object, typed as the original `WorkspaceItem`. */ asOriginalType2__(): WorkspaceItemOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(WorkspaceItem.prototype, 'constructor2__')`. * * @param _workspace - The workspace the item was created with. * @param _id - The item id the item was created with. */ constructor2__(_workspace?: Workspace, _id?: string): void; /** * Removes the item from its parent, if it has one. */ detach(): void; /** * Gets the root container the item lives in: the nearest `WorkspaceContainer` among the item and its ancestors, * falling back to the workspace's root split when there is none, as Obsidian does. * * @returns The container. * @throws An `Error` when the item has no container ancestor and was created without a workspace. */ getContainer(): WorkspaceContainerOriginal; /** * Gets the root item of the layout tree the item belongs to, by walking up through its parents. * * @returns The topmost ancestor, or the item itself when it has no parent. */ getRoot(): WorkspaceItem; /** * Serializes the item, as Obsidian does: its id and type, and its dimension when it has one. Subclasses add their own * keys. * * @returns The serialized item. */ serialize(): SerializedWorkspaceItem; /** * Sets the item's share of its parent split. As in Obsidian, a value outside the open range `(0, 100)` is stored as * `null`; the mock renders nothing, so it only keeps the value. * * @param dimension - The flex-grow value, or `null` to take the natural share. */ setDimension(dimension: null | number): void; /** * Sets the item's parent. `WorkspaceParent` calls it when it adopts or releases a child. * * @param parent - The new parent, or `null` to leave the item without one. */ setParent(parent: null | WorkspaceParentOriginal): void; private findContainer; private hasParent; }