All files / src/libs/EditableDataView EditableDataView.ts

0% Statements 0/39
0% Branches 0/20
0% Functions 0/6
0% Lines 0/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119                                                                                                                                                                                                                                             
import { Component } from 'obsidian';
import DateComponent from './Components/DateComponent';
import DropdownComponent from './Components/DropdownComponent';
import LinkComponent from './Components/LinkComponent';
import TextareaComponent from './Components/TextareaComponent';
import TextComponent from './Components/TextComponent';
 
/**
 * Represents an editable data view that allows adding various components.
 */
export default class EditableDataView {
    private readonly _container: HTMLElement | DocumentFragment;
    private readonly _component: Component;
    private readonly _attributesList: Record<string, string> = {};
 
    /**
     * Creates a new instance of EditableDataView.
     * @param container - The container element where the components will be added.
     * @param component - The parent component.
     */
    constructor(
        container: HTMLElement | DocumentFragment,
        component: Component,
    ) {
        this._container = container;
        this._component = component;
    }
 
    /**
     * Adds a text component to the data view.
     * @param configure - A function that configures the text component.
     * @returns The EditableDataView instance.
     */
    public addText(
        configure: (component: TextComponent) => void,
    ): EditableDataView {
        const textComponent = new TextComponent(this._component);
        configure(textComponent);
        textComponent.finalize();
        textComponent.thenCallback?.(textComponent.container);
 
        this._container.append(textComponent.container);
 
        return this;
    }
 
    /**
     * Adds a textarea component to the data view.
     * @param configure - A function that configures the textarea component.
     * @returns The EditableDataView instance.
     */
    public addTextarea(
        configure: (component: TextareaComponent) => void,
    ): EditableDataView {
        const textComponent = new TextareaComponent(this._component);
        configure(textComponent);
        textComponent.finalize();
        textComponent.thenCallback?.(textComponent.container);
 
        this._container.append(textComponent.container);
 
        return this;
    }
 
    /**
     * Adds a link component to the data view.
     * @param configure - A function that configures the link component.
     * @returns The EditableDataView instance.
     */
    public addLink(
        configure: (component: LinkComponent) => void,
    ): EditableDataView {
        const linkComponent = new LinkComponent(this._component);
        configure(linkComponent);
        linkComponent.finalize();
        linkComponent.thenCallback?.(linkComponent.container);
 
        this._container.appendChild(linkComponent.container);
 
        return this;
    }
 
    /**
     * Adds a date component to the data view.
     * @param configure - A function that configures the date component.
     * @returns The EditableDataView instance.
     */
    public addDate(
        configure: (component: DateComponent) => void,
    ): EditableDataView {
        const dateComponent = new DateComponent(this._component);
        configure(dateComponent);
        dateComponent.finalize();
        dateComponent.thenCallback?.(dateComponent.container);
 
        this._container.append(dateComponent.container);
 
        return this;
    }
 
    /**
     * Adds a dropdown component to the data view.
     * @param configure - A function that configures the dropdown component.
     * @returns The EditableDataView instance.
     */
    public addDropdown(
        configure: (component: DropdownComponent) => void,
    ): EditableDataView {
        const dropdownComponent = new DropdownComponent(this._component);
        configure(dropdownComponent);
        dropdownComponent.finalize();
        dropdownComponent.thenCallback?.(dropdownComponent.container);
 
        this._container.appendChild(dropdownComponent.container);
 
        return this;
    }
}
 
Zur TypeDoc-Dokumentation