/** * @file * * Mock of Obsidian's `SliderComponent`, a range input bound to a numeric value. */ import type { SliderComponent as SliderComponentOriginal } from 'obsidian'; import { ValueComponent } from './ValueComponent.mjs'; /** * Mock of Obsidian's `SliderComponent`. * * As in Obsidian, the value lives in {@link SliderComponent.sliderEl}, and the limits are its `min`, `max` and `step` * attributes. A browser keeps a range input's value inside those limits and on a step; jsdom does not, so the mock * applies the same rules itself whenever it reads the value. {@link SliderComponent.setValue} calls the change * callback only when the value actually changes, and the element's `input` and `change` events call it as Obsidian * does, depending on {@link SliderComponent.instant}. */ export declare class SliderComponent extends ValueComponent { /** * The callback registered with {@link SliderComponent.onChange}, or `null`. */ changeCallback: ((value: number) => unknown) | null; /** * The formatter set with {@link SliderComponent.setDisplayFormat}, or `null`. */ displayFormat: ((value: number) => string) | null; /** * Whether the change callback runs on every `input` event rather than only on `change`. */ instant: boolean; /** * The underlying `` element. */ sliderEl: HTMLInputElement; private hasExplicitValue; /** * Creates a slider and appends its range input to the container. * * @param containerEl - The element to create the slider in. */ constructor(containerEl: HTMLElement); /** * Mock-only factory: creates a slider, spyable via `vi.spyOn(SliderComponent, 'create__')`. * * @param containerEl - The element to create the slider in. * @returns The new slider. */ static create__(containerEl: HTMLElement): SliderComponent; /** * Mock-only: views a value typed as Obsidian's `SliderComponent` as this mock. * * @param value - The value typed as the original `SliderComponent`. * @returns The same object, typed as the mock. */ static fromOriginalType3__(value: SliderComponentOriginal): SliderComponent; /** * Mock-only: views this mock as Obsidian's `SliderComponent` type. * * @returns The same object, typed as the original `SliderComponent`. */ asOriginalType3__(): SliderComponentOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(SliderComponent.prototype, 'constructor3__')`. * * @param _containerEl - The container the slider was created in. */ constructor3__(_containerEl: HTMLElement): void; /** * Gets the slider's current value, the way a browser reports a range input's `valueAsNumber`. * * @returns The element's value clamped to the limits and rounded to the nearest step; the middle of the range * until a value is set. */ getValue(): number; /** * Gets the value formatted for display. * * @returns The value passed through the display format when one is set; otherwise the value with two decimals * when the step is `any` or below 1, or as a plain number. */ getValuePretty(): string; /** * Registers the callback invoked when the value changes, replacing any previous one. * * @param callback - Called with the new value. * @returns This component, for chaining. */ onChange(callback: (value: number) => unknown): this; /** * Disables or enables the slider and its range input. * * @param disabled - Whether the slider is disabled. * @returns This component, for chaining. */ setDisabled(disabled: boolean): this; /** * Sets a custom formatter for the value shown next to the slider, used by {@link SliderComponent.getValuePretty}. * * @param format - Formats a value for display. * @returns This component, for chaining. */ setDisplayFormat(format: (value: number) => string): this; /** * Shows the value in a tooltip while dragging. Obsidian deprecates it, since the value is now always shown inline, * and its implementation does nothing either. * * @returns This component, for chaining. */ setDynamicTooltip(): this; /** * Sets whether the change callback runs while the slider is dragged (`input` events) rather than on release * (`change` events). * * @param instant - Whether to call the change callback during dragging. * @returns This component, for chaining. */ setInstant(instant: boolean): this; /** * Sets the slider's range and step as the input's `min`, `max` and `step` attributes. The value is re-read against * the new limits, as a browser does. * * @param min - The minimum value; `null` means `0`. * @param max - The maximum value; `null` means `100`. * @param step - The step size, or `'any'` for no stepping. * @returns This component, for chaining. */ setLimits(min: null | number, max: null | number, step: 'any' | number): this; /** * Sets the slider's value. When the element's value changes, it is stored and the change callback is called with * `value` as given; an unchanged value does nothing. The value read back is kept within the limits and on a step. * * @param value - The new value. * @returns This component, for chaining. */ setValue(value: number): this; }