Skip to content

Commit

Permalink
eslint: unify indentation to 2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
niczyja committed Jan 26, 2024
1 parent de78c7e commit 84ec61b
Show file tree
Hide file tree
Showing 9 changed files with 496 additions and 496 deletions.
76 changes: 38 additions & 38 deletions src/header_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
import { Component, getIcon } from 'obsidian';

export class HeaderMenu extends Component {
containerEl: HTMLElement;
containerEl: HTMLElement;

constructor() {
super();
this.containerEl = createDiv({ cls: 'nav-header' });
}
constructor() {
super();
this.containerEl = createDiv({ cls: 'nav-header' });
}

onload(): void {
this.containerEl.createDiv({ cls: 'nav-buttons-container' });
}
onload(): void {
this.containerEl.createDiv({ cls: 'nav-buttons-container' });
}

onunload(): void {
this.containerEl.empty();
}
onunload(): void {
this.containerEl.empty();
}

addItem(cb: (item: HeaderMenuItem) => any) {
cb(new HeaderMenuItem(<HTMLElement>this.containerEl.children[0]));
}
addItem(cb: (item: HeaderMenuItem) => any) {
cb(new HeaderMenuItem(<HTMLElement>this.containerEl.children[0]));
}
}

export class HeaderMenuItem {
private contentEl: HTMLElement;

constructor(parent: HTMLElement) {
this.contentEl = parent.createDiv({ cls: 'clickable-icon nav-action-button' })
}

setIcon(icon: string): HeaderMenuItem {
this.contentEl.empty();
const svg = getIcon(icon);
if (svg != null)
this.contentEl.appendChild(<Node>svg);
return this;
}

setLabel(label: string | null): HeaderMenuItem {
this.contentEl.setAttr('aria-label', label);
return this;
}

onClick(cb: (el: HeaderMenuItem) => any): HeaderMenuItem {
const that = this;
this.contentEl.onClickEvent((_ev) => cb(that));
return this;
}
private contentEl: HTMLElement;

constructor(parent: HTMLElement) {
this.contentEl = parent.createDiv({ cls: 'clickable-icon nav-action-button' })
}

setIcon(icon: string): HeaderMenuItem {
this.contentEl.empty();
const svg = getIcon(icon);
if (svg != null)
this.contentEl.appendChild(<Node>svg);
return this;
}

setLabel(label: string | null): HeaderMenuItem {
this.contentEl.setAttr('aria-label', label);
return this;
}

onClick(cb: (el: HeaderMenuItem) => any): HeaderMenuItem {
const that = this;
this.contentEl.onClickEvent((_ev) => cb(that));
return this;
}
}
98 changes: 49 additions & 49 deletions src/link_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@ import { ArcSidebarItem } from 'model';
import { Component, getIcon } from 'obsidian';

export class LinkTree extends Component {
public containerEl: HTMLElement;
public title: string;
private _items: ArcSidebarItem[];
private itemsEl: HTMLElement;
public containerEl: HTMLElement;
public title: string;
private _items: ArcSidebarItem[];
private itemsEl: HTMLElement;

constructor(items: ArcSidebarItem[], title: string) {
super();
this.containerEl = createDiv({ cls: 'nav-files-container' });
this._items = items;
this.title = title;
}
constructor(items: ArcSidebarItem[], title: string) {
super();
this.containerEl = createDiv({ cls: 'nav-files-container' });
this._items = items;
this.title = title;
}

public get items() {
return this._items;
}
public get items() {
return this._items;
}

public set items(newItems: ArcSidebarItem[]) {
this._items = newItems;
this.populateItems();
}
public set items(newItems: ArcSidebarItem[]) {
this._items = newItems;
this.populateItems();
}

onload(): void {
const rootEl = this.containerEl.createDiv({ cls: 'tree-item nav-folder mod-root' });
rootEl
.createDiv({ cls: 'tree-item-self nav-folder-title' })
.createDiv({ cls: 'tree-item-inner nav-folder-title-content', text: this.title });
this.itemsEl = rootEl.createDiv({ cls: 'tree-item-children nav-folder-children' });
onload(): void {
const rootEl = this.containerEl.createDiv({ cls: 'tree-item nav-folder mod-root' });
rootEl
.createDiv({ cls: 'tree-item-self nav-folder-title' })
.createDiv({ cls: 'tree-item-inner nav-folder-title-content', text: this.title });
this.itemsEl = rootEl.createDiv({ cls: 'tree-item-children nav-folder-children' });

this.populateItems();
}
this.populateItems();
}

onunload(): void {
this.containerEl.empty();
}
onunload(): void {
this.containerEl.empty();
}

private populateItems() {
this.itemsEl.empty();
this._items.forEach((item) => this.addItem(item, this.itemsEl));
}
private populateItems() {
this.itemsEl.empty();
this._items.forEach((item) => this.addItem(item, this.itemsEl));
}

private addItem(item: ArcSidebarItem, rootEl: HTMLElement) {
const isFolder: boolean = item.children.length != 0;
const cls: string = isFolder ? 'nav-folder' : 'nav-file';
private addItem(item: ArcSidebarItem, rootEl: HTMLElement) {
const isFolder: boolean = item.children.length != 0;
const cls: string = isFolder ? 'nav-folder' : 'nav-file';

const itemEl = rootEl.createDiv({ cls: 'tree-item ' + cls })
const titleEl = itemEl.createDiv({ cls: 'tree-item-self ' + cls + '-title' }, (el) => {
if (!isFolder)
el.onClickEvent((ev) => ev.doc.win.open(item.url || undefined));
});
const itemEl = rootEl.createDiv({ cls: 'tree-item ' + cls })
const titleEl = itemEl.createDiv({ cls: 'tree-item-self ' + cls + '-title' }, (el) => {
if (!isFolder)
el.onClickEvent((ev) => ev.doc.win.open(item.url || undefined));
});

if (isFolder) {
const childrenEl = rootEl.createDiv({ cls: 'tree-item-children nav-folder-children' });
item.children.forEach((child) => this.addItem(child, childrenEl));
if (isFolder) {
const childrenEl = rootEl.createDiv({ cls: 'tree-item-children nav-folder-children' });
item.children.forEach((child) => this.addItem(child, childrenEl));

titleEl
.createDiv({ cls: 'tree-item-icon collapse-icon nav-folder-collapse-indicator' })
.appendChild(<Node>getIcon('right-triangle'));
}
titleEl
.createDiv({ cls: 'tree-item-icon collapse-icon nav-folder-collapse-indicator' })
.appendChild(<Node>getIcon('right-triangle'));
}

titleEl.createDiv({ cls: 'tree-item-inner ' + cls + '-title-content', text: item.title });
}
titleEl.createDiv({ cls: 'tree-item-inner ' + cls + '-title-content', text: item.title });
}
}
184 changes: 92 additions & 92 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,96 @@ import { parseArcJson } from 'parser';
import { ArcSidebarModel } from 'model';

export default class ArcSidebar extends Plugin {
settings: ArcSidebarSettings;
data: ArcSidebarModel;

async onload(): Promise<void> {
const { workspace } = this.app;

addIcon('arc', `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-drafting-compass"><circle cx="12" cy="5" r="2"/><path d="m3 21 8.02-14.26"/><path d="m12.99 6.74 1.93 3.44"/><path d="M19 12c-3.87 4-10.13 4-14 0"/><path d="m21 21-2.16-3.84"/></svg>`);

await this.loadSettings();
this.addSettingTab(new ArcSidebarSettingsTab(this.app, this));
this.data = await parseArcJson(this.settings.jsonPath);

this.registerView(VIEW_TYPE_OUTLINE, (leaf) => new ArcSidebarOutlineView(this, leaf));
this.registerView(VIEW_TYPE_NOTE, (leaf) => new ArcSidebarNoteView(this, leaf));

workspace.onLayoutReady(() => {
this.initView(VIEW_TYPE_OUTLINE, workspace.getLeftLeaf(false));
this.initView(VIEW_TYPE_NOTE, workspace.getRightLeaf(false));

workspace.rootSplit.win.addEventListener('focus', async (_event) => {
this.data = await parseArcJson(this.settings.jsonPath);
});
});

this.addCommand({
id: 'open-arc-sidebar-outline',
name: 'Open outline view',
callback: async () => {
await this.revealOutlineView();
}
});
this.addCommand({
id: 'open-arc-sidebar-note',
name: 'Open note view',
callback: async () => {
await this.revealNoteView();
}
});

this.registerEvent(workspace.on('editor-menu', (menu, editor, view) => {
menu.addItem((item) => {
item
.setTitle('Open Arc Note View')
.setIcon('arc')
.onClick(async () => {
await this.revealNoteView();
});
});
}));
}

async onunload(): Promise<void> {
}

async loadSettings(): Promise<void> {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings(): Promise<void> {
await this.saveData(this.settings);
}

async initView(viewType: string, leaf: WorkspaceLeaf): Promise<void> {
this.app.workspace.detachLeavesOfType(viewType);
await leaf.setViewState({ type: viewType, active: true }); //TODO: change active to false for prod
}

async revealOutlineView(): Promise<void> {
const { workspace } = this.app;

const leaves = workspace.getLeavesOfType(VIEW_TYPE_OUTLINE);
if (leaves.length > 0) {
workspace.revealLeaf(leaves[0]);
} else {
const left = workspace.getLeftLeaf(false);
await left.setViewState({ type: VIEW_TYPE_OUTLINE, active: true });
workspace.revealLeaf(left);
}
}

async revealNoteView(): Promise<void> {
const { workspace } = this.app;

const leaves = workspace.getLeavesOfType(VIEW_TYPE_NOTE);
if (leaves.length > 0) {
workspace.revealLeaf(leaves[0]);
} else {
const right = workspace.getRightLeaf(false);
await right.setViewState({ type: VIEW_TYPE_NOTE, active: true });
workspace.revealLeaf(right);
}
}
settings: ArcSidebarSettings;
data: ArcSidebarModel;

async onload(): Promise<void> {
const { workspace } = this.app;

addIcon('arc', `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-drafting-compass"><circle cx="12" cy="5" r="2"/><path d="m3 21 8.02-14.26"/><path d="m12.99 6.74 1.93 3.44"/><path d="M19 12c-3.87 4-10.13 4-14 0"/><path d="m21 21-2.16-3.84"/></svg>`);

await this.loadSettings();
this.addSettingTab(new ArcSidebarSettingsTab(this.app, this));
this.data = await parseArcJson(this.settings.jsonPath);

this.registerView(VIEW_TYPE_OUTLINE, (leaf) => new ArcSidebarOutlineView(this, leaf));
this.registerView(VIEW_TYPE_NOTE, (leaf) => new ArcSidebarNoteView(this, leaf));

workspace.onLayoutReady(() => {
this.initView(VIEW_TYPE_OUTLINE, workspace.getLeftLeaf(false));
this.initView(VIEW_TYPE_NOTE, workspace.getRightLeaf(false));

workspace.rootSplit.win.addEventListener('focus', async (_event) => {
this.data = await parseArcJson(this.settings.jsonPath);
});
});

this.addCommand({
id: 'open-arc-sidebar-outline',
name: 'Open outline view',
callback: async () => {
await this.revealOutlineView();
}
});
this.addCommand({
id: 'open-arc-sidebar-note',
name: 'Open note view',
callback: async () => {
await this.revealNoteView();
}
});

this.registerEvent(workspace.on('editor-menu', (menu, editor, view) => {
menu.addItem((item) => {
item
.setTitle('Open Arc Note View')
.setIcon('arc')
.onClick(async () => {
await this.revealNoteView();
});
});
}));
}

async onunload(): Promise<void> {
}

async loadSettings(): Promise<void> {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings(): Promise<void> {
await this.saveData(this.settings);
}

async initView(viewType: string, leaf: WorkspaceLeaf): Promise<void> {
this.app.workspace.detachLeavesOfType(viewType);
await leaf.setViewState({ type: viewType, active: true }); //TODO: change active to false for prod
}

async revealOutlineView(): Promise<void> {
const { workspace } = this.app;

const leaves = workspace.getLeavesOfType(VIEW_TYPE_OUTLINE);
if (leaves.length > 0) {
workspace.revealLeaf(leaves[0]);
} else {
const left = workspace.getLeftLeaf(false);
await left.setViewState({ type: VIEW_TYPE_OUTLINE, active: true });
workspace.revealLeaf(left);
}
}

async revealNoteView(): Promise<void> {
const { workspace } = this.app;

const leaves = workspace.getLeavesOfType(VIEW_TYPE_NOTE);
if (leaves.length > 0) {
workspace.revealLeaf(leaves[0]);
} else {
const right = workspace.getRightLeaf(false);
await right.setViewState({ type: VIEW_TYPE_NOTE, active: true });
workspace.revealLeaf(right);
}
}
}
Loading

0 comments on commit 84ec61b

Please sign in to comment.