mirror of
https://github.com/ozntel/file-explorer-note-count.git
synced 2026-07-22 05:40:24 +00:00
style: fix eslint errors
This commit is contained in:
parent
ddd442b709
commit
132019d8d9
5 changed files with 38 additions and 34 deletions
|
|
@ -5,7 +5,7 @@ module.exports = {
|
|||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
},
|
||||
extends: ['prettier', 'plugin:prettier/recommended', 'eslint:recommended'],
|
||||
extends: ['prettier', 'plugin:prettier/recommended'],
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
|
|
|
|||
|
|
@ -1,27 +1,28 @@
|
|||
import FileExplorerNoteCount from 'main';
|
||||
import {
|
||||
isFolder,
|
||||
iterateItems,
|
||||
getParentPath,
|
||||
withSubfolderClass,
|
||||
AbstractFileFilter,
|
||||
} from 'misc';
|
||||
import { AFItem, FolderItem, TAbstractFile, TFolder } from 'obsidian';
|
||||
import './styles/folder-count.css';
|
||||
|
||||
function countFolderChildren(folder: TFolder, filter: AbstractFileFilter) {
|
||||
import FileExplorerNoteCount from 'main';
|
||||
import {
|
||||
AbstractFileFilter,
|
||||
getParentPath,
|
||||
isFolder,
|
||||
iterateItems,
|
||||
withSubfolderClass,
|
||||
} from 'misc';
|
||||
import { AFItem, FolderItem, TAbstractFile, TFolder } from 'obsidian';
|
||||
|
||||
const countFolderChildren = (folder: TFolder, filter: AbstractFileFilter) => {
|
||||
let count = 0;
|
||||
for (const af of folder.children) {
|
||||
if (filter(af)) count++;
|
||||
if (af instanceof TFolder) count += countFolderChildren(af, filter);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
export function updateCount(
|
||||
export const updateCount = (
|
||||
file: string | TAbstractFile,
|
||||
plugin: FileExplorerNoteCount,
|
||||
) {
|
||||
) => {
|
||||
if (!plugin.fileExplorer) throw new Error('fileExplorer not found');
|
||||
const explorer = plugin.fileExplorer;
|
||||
|
||||
|
|
@ -47,9 +48,9 @@ export function updateCount(
|
|||
} else parent = file.parent;
|
||||
|
||||
iterate(parent);
|
||||
}
|
||||
};
|
||||
|
||||
export function setupCount(plugin: FileExplorerNoteCount, revert = false) {
|
||||
export const setupCount = (plugin: FileExplorerNoteCount, revert = false) => {
|
||||
if (!plugin.fileExplorer) throw new Error('fileExplorer not found');
|
||||
|
||||
iterateItems(plugin.fileExplorer.fileItems, (item: AFItem) => {
|
||||
|
|
@ -57,9 +58,9 @@ export function setupCount(plugin: FileExplorerNoteCount, revert = false) {
|
|||
if (revert) removeCount(item);
|
||||
else setCount(item, plugin.fileFilter);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function setCount(item: FolderItem, filter: AbstractFileFilter) {
|
||||
const setCount = (item: FolderItem, filter: AbstractFileFilter) => {
|
||||
if (item.file.isRoot()) return;
|
||||
const count = countFolderChildren(item.file, filter);
|
||||
item.titleEl.dataset['count'] = count.toString();
|
||||
|
|
@ -68,9 +69,9 @@ function setCount(item: FolderItem, filter: AbstractFileFilter) {
|
|||
Array.isArray(item.file.children) &&
|
||||
item.file.children.findIndex((af) => af instanceof TFolder) !== -1,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
function removeCount(item: FolderItem) {
|
||||
const removeCount = (item: FolderItem) => {
|
||||
if (item.titleEl.dataset['count']) delete item.titleEl.dataset['count'];
|
||||
item.titleEl.removeClass(withSubfolderClass);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
12
src/main.ts
12
src/main.ts
|
|
@ -1,10 +1,12 @@
|
|||
import { FileExplorer, Plugin, TFile } from 'obsidian';
|
||||
import { DEFAULT_SETTINGS, FENoteCountSettingTab } from './settings';
|
||||
import { setupCount, updateCount } from './folder-count';
|
||||
import { dirname } from 'path';
|
||||
import { withSubfolderClass, AbstractFileFilter } from 'misc';
|
||||
import './styles/patch.css';
|
||||
|
||||
import { AbstractFileFilter, withSubfolderClass } from 'misc';
|
||||
import { FileExplorer, Plugin, TFile } from 'obsidian';
|
||||
import { dirname } from 'path';
|
||||
|
||||
import { setupCount, updateCount } from './folder-count';
|
||||
import { DEFAULT_SETTINGS, FENoteCountSettingTab } from './settings';
|
||||
|
||||
export default class FileExplorerNoteCount extends Plugin {
|
||||
settings = DEFAULT_SETTINGS;
|
||||
|
||||
|
|
|
|||
14
src/misc.ts
14
src/misc.ts
|
|
@ -1,9 +1,9 @@
|
|||
import {
|
||||
AFItem,
|
||||
FolderItem,
|
||||
TFolder,
|
||||
FileExplorer,
|
||||
FolderItem,
|
||||
TAbstractFile,
|
||||
TFolder,
|
||||
} from 'obsidian';
|
||||
import { dirname } from 'path';
|
||||
|
||||
|
|
@ -12,15 +12,15 @@ export const withSubfolderClass = 'oz-with-subfolder';
|
|||
export const isFolder = (item: AFItem): item is FolderItem =>
|
||||
(item as FolderItem).file instanceof TFolder;
|
||||
|
||||
export function iterateItems(
|
||||
export const iterateItems = (
|
||||
items: FileExplorer['fileItems'],
|
||||
callback: (item: AFItem) => any,
|
||||
): void {
|
||||
): void => {
|
||||
for (const key in items) {
|
||||
if (!Object.prototype.hasOwnProperty.call(items, key)) continue;
|
||||
callback(items[key]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getParentPath = (src: string) => {
|
||||
const path = dirname(src);
|
||||
|
|
@ -30,7 +30,7 @@ export const getParentPath = (src: string) => {
|
|||
|
||||
export type AbstractFileFilter = (af: TAbstractFile) => boolean;
|
||||
|
||||
export function equals(arr1: any, arr2: any) {
|
||||
export const equals = (arr1: any, arr2: any) => {
|
||||
// if the other array is a falsy value, return
|
||||
if (!Array.isArray(arr1) || !Array.isArray(arr2)) return false;
|
||||
|
||||
|
|
@ -38,4 +38,4 @@ export function equals(arr1: any, arr2: any) {
|
|||
if (arr1.length != arr2.length) return false;
|
||||
|
||||
return arr1.every((v, i) => v === arr2[i]);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { equals } from 'misc';
|
||||
import { PluginSettingTab, App, Setting } from 'obsidian';
|
||||
import { App, PluginSettingTab, Setting } from 'obsidian';
|
||||
|
||||
import FileExplorerNoteCount from './main';
|
||||
|
||||
export interface FENoteCountSettings {
|
||||
|
|
|
|||
Loading…
Reference in a new issue