diff --git a/.prettierrc b/.prettierrc index d0abbb6..e8ab184 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,12 @@ { "singleQuote": true, "tabWidth": 4, - "trailingComma": "all", + "printWidth": 155, + "semi": true, + "trailingComma": "es5", + "bracketSpacing": true, + "arrowParens": "always", + "jsxBracketSameLine": true, "overrides": [ { "files": ".prettierrc", diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 3aa6b62..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,62 +0,0 @@ -# [1.2.0](https://github.com/ozntel/file-explorer-note-count/compare/1.1.3...1.2.0) (2021-11-20) - - -### Bug Fixes - -* **initialize:** fix file explorer count failed to update when workspace changes ([22546ba](https://github.com/ozntel/file-explorer-note-count/commit/22546ba94f18c1b103785d69cf582d67d80a91f9)), closes [#8](https://github.com/ozntel/file-explorer-note-count/issues/8) - - -### Features - -* exclude folder note from counts ([a7083c7](https://github.com/ozntel/file-explorer-note-count/commit/a7083c7159e06214265e8511a47888e0f3e3bf4b)), closes [#7](https://github.com/ozntel/file-explorer-note-count/issues/7) - -## [1.1.3](https://github.com/ozntel/file-explorer-note-count/compare/1.1.2...1.1.3) (2021-06-22) - - -### Bug Fixes - -* fix vault count shown in theme that hide root folder ([d9dd101](https://github.com/ozntel/file-explorer-note-count/commit/d9dd1011f0390523774c70f79c7f4ef9e570c1bc)) - -## [1.1.2](https://github.com/ozntel/file-explorer-note-count/compare/1.1.1...1.1.2) (2021-06-22) - - -### Bug Fixes - -* **folder-count.ts:** fix count not showing up in root(vault) folder ([61089e2](https://github.com/ozntel/file-explorer-note-count/commit/61089e29ead927e7ccf6986638a69746b4d34994)), closes [#4](https://github.com/ozntel/file-explorer-note-count/issues/4) - -## [1.1.1](https://github.com/ozntel/file-explorer-note-count/compare/1.1.0...1.1.1) (2021-06-21) - - -### Bug Fixes - -* **main.ts:** fix class oz-show-all-num not removed when unload ([8dfd4f7](https://github.com/ozntel/file-explorer-note-count/commit/8dfd4f78a7b5437ae3fb1d004201e3cb43172c5a)) -* fix move folder reports error ([699507d](https://github.com/ozntel/file-explorer-note-count/commit/699507d93e2d78fe5fd0304e2ffaf66b48e20ceb)) - - -### Performance Improvements - -* use debounce for vault event ([a4498fd](https://github.com/ozntel/file-explorer-note-count/commit/a4498fdec90dddb09eb5b47f3865d2a0dce39a42)) - -# [1.1.0](https://github.com/ozntel/file-explorer-note-count/compare/1.0.0...1.1.0) (2021-06-07) - - -### Bug Fixes - -* fix try to update count on old path of renamed folder ([90eb6f8](https://github.com/ozntel/file-explorer-note-count/commit/90eb6f84aa8e9d2544e1e6df2f61134f099fbb3a)) -* **folder-count.ts:** fix folder not counting files in nested folders ([651b47d](https://github.com/ozntel/file-explorer-note-count/commit/651b47d16288f6b604f5d1ddfcfbc94a0dc185d4)) -* fix count overlap with title content when title is long ([f9f3a75](https://github.com/ozntel/file-explorer-note-count/commit/f9f3a758d10026590366f28c4c0b595b3449d518)) -* fix default theme num style ([deb2422](https://github.com/ozntel/file-explorer-note-count/commit/deb242206722b0a2f81327d0ee3efac9e8ee908d)) - - -### Features - -* add file extension filter ([9c5ef53](https://github.com/ozntel/file-explorer-note-count/commit/9c5ef53524526f7ca3e529cfe56e5fed61b7f903)) -* add option to show only markdown notes ([577b3f8](https://github.com/ozntel/file-explorer-note-count/commit/577b3f8da3e16c989d3eb0c1079020b347131e79)) -* **folder-note.css:** optimize num style ([df360b4](https://github.com/ozntel/file-explorer-note-count/commit/df360b4f2f84026c5168e8b48a4e467d00f2d5d3)) -* hide num when expanded for folder with subfolders ([da322c4](https://github.com/ozntel/file-explorer-note-count/commit/da322c4e159a93f2dabb7fd7f74d9c81d15170ca)) -* migrate code from alx-folder-note ([8d92e01](https://github.com/ozntel/file-explorer-note-count/commit/8d92e018f82f9cd5f0efb0bddf599d8efa8d1c69)) - - - -# [1.0.0](https://github.com/ozntel/file-explorer-note-count/compare/1.0.0...1.1.0) (2021-06-02) - diff --git a/README.md b/README.md index 986ee21..f93e19d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ## Brief Explanation -- This plugin helps you to see the number of elements you have under all available folders within your file explorer. +- This plugin helps you to see the number of elements you have under all available folders within your file explorer. -- Counts will include total number of all elements under a folder and its sub-folders. +- Counts will include total number of all elements under a folder and its sub-folders. -- By default, expanded folders won't have the number of notes in case they have sub-folders. +- By default, expanded folders won't have the number of notes in case they have sub-folders. ## Sample View @@ -14,13 +14,10 @@ ## Settings -- You can turn on the option for viewing the counts for all folders including the expanded folders. Otherwise, expanded folders won't have the number unless the expanded folder does not include any sub-folder. +- You can turn on the option for viewing the counts for all folders including the expanded folders. Otherwise, expanded folders won't have the number unless the expanded folder does not include any sub-folder. -- You can include/exclude folder note from file counts (excluded by default) - - Note: [folder-note-core](https://github.com/aidenlx/folder-note-core) required, install and enable this plugin to take effects - ## Contact If you have any issue or you have any suggestion, please feel free to reach me out directly using contact page of my website [ozan.pl/contact/](https://www.ozan.pl/contact/) or directly to . diff --git a/package.json b/package.json index 52288e6..4fa7bfd 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "author": "", "license": "MIT", "devDependencies": { - "@aidenlx/folder-note-core": "^1.2.2", "@release-it/bumper": "^2.0.0", "@release-it/conventional-changelog": "^2.0.1", "@rollup/plugin-commonjs": "^18.0.0", diff --git a/rollup.config.js b/rollup.config.js index 64d5c3b..29e6153 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,24 +3,17 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'; import typescript from '@rollup/plugin-typescript'; import copy from 'rollup-plugin-copy'; import css from 'rollup-plugin-import-css'; +import { env } from 'process'; -const isProd = process.env.BUILD === 'production'; - -const banner = `/* -THIS IS A GENERATED/BUNDLED FILE BY ROLLUP -if you want to view the source visit the plugins github repository -*/ -`; +const isProd = env.NODE_ENV === 'production'; export default { - input: 'src/fec-main.ts', + input: 'src/main.ts', output: { - file: 'build/main.js', - sourcemap: 'inline', - sourcemapExcludeSources: isProd, + file: isProd ? 'build/main.js' : 'main.js', + sourcemap: !isProd, format: 'cjs', exports: 'default', - banner, }, external: ['obsidian'], plugins: [ diff --git a/src/fec-main.ts b/src/fec-main.ts deleted file mode 100644 index fbf2148..0000000 --- a/src/fec-main.ts +++ /dev/null @@ -1,164 +0,0 @@ -import './styles/patch.css'; - -import { getApi } from '@aidenlx/folder-note-core'; -import { - AbstractFileFilter, - rootHiddenClass, - showAllNumbersClass, - withSubfolderClass, -} from 'misc'; -import { around } from 'monkey-around'; -import { FileExplorer, Plugin, TFile } from 'obsidian'; -import { VaultHandler } from 'vault-handler'; - -import { setupCount } from './folder-count'; -import { DEFAULT_SETTINGS, FENoteCountSettingTab } from './settings'; - -export default class FileExplorerNoteCount extends Plugin { - settings = DEFAULT_SETTINGS; - - fileExplorer?: FileExplorer; - - vaultHandler = new VaultHandler(this); - - /** compatible with theme that hide root folder */ - doHiddenRoot = (revert = false) => { - if (!this.fileExplorer) { - console.error('file-explorer not found'); - return; - } - const root = this.fileExplorer.fileItems['/']; - const styles = getComputedStyle(root.innerEl); - const setup = () => { - const shouldHide = - styles.display === 'none' || - styles.color === 'rgba(0, 0, 0, 0)'; - root.selfEl.toggleClass(rootHiddenClass, !revert && shouldHide); - }; - if (styles.display !== '') setup(); - else { - let count = 0; - const doId = window.setInterval(() => { - if (count > 10) { - console.error('%o styles empty', root.innerEl); - window.clearInterval(doId); - } else if (styles.display === '') { - count++; - } else { - setup(); - window.clearInterval(doId); - } - }, 100); - } - }; - - initialize = (revert = false) => { - const doWithFileExplorer = (callback: (view: FileExplorer) => void) => { - let leaves, - count = 0; - const tryGetView = () => { - leaves = this.app.workspace.getLeavesOfType('file-explorer'); - if (leaves.length === 0) { - if (count++ > 5) - console.error('failed to get file-explorer'); - else { - console.log('file-explorer not found, retrying...'); - setTimeout(tryGetView, 500); - } - } else { - if (leaves.length > 1) - console.warn('more then one file-explorer'); - callback(leaves[0].view as FileExplorer); - } - }; - tryGetView(); - }; - const getViewHandler = (revert: boolean) => (view: FileExplorer) => { - this.fileExplorer = view; - - setupCount(this, revert); - this.doHiddenRoot(revert); - if (!revert) { - this.registerEvent( - this.app.workspace.on('css-change', this.doHiddenRoot), - ); - this.vaultHandler.registerVaultEvent(); - if (this.settings.showAllNumbers) - document.body.addClass('oz-show-all-num'); - } else { - for (const el of document.getElementsByClassName( - withSubfolderClass, - )) { - el.removeClass(withSubfolderClass); - } - document.body.removeClass(showAllNumbersClass); - } - - if (!revert) { - // when file explorer is closed (workspace changed) - // try to update fehanlder with new file explorer instance - this.register( - around(view, { - onClose: (next) => - function (this: FileExplorer) { - setTimeout( - () => - doWithFileExplorer( - getViewHandler(false), - ), - 1e3, - ); - return next.apply(this); - }, - }), - ); - } - }; - doWithFileExplorer(getViewHandler(revert)); - }; - - async onload() { - console.log('loading FileExplorerNoteCount'); - this.addSettingTab(new FENoteCountSettingTab(this.app, this)); - await this.loadSettings(); - this.app.workspace.onLayoutReady(this.initialize); - } - - onunload() { - console.log('unloading FileExplorerNoteCount'); - this.initialize(true); - } - - async loadSettings() { - this.settings = { ...this.settings, ...(await this.loadData()) }; - } - - async saveSettings() { - await this.saveData(this.settings); - } - - reloadCount() { - setupCount(this); - } - - get fileFilter(): AbstractFileFilter { - let list = this.settings.filterList; - return (af) => { - if (af instanceof TFile) { - let api; - if ( - this.settings.filterFolderNote && - (api = getApi(this)) && - !!api.getFolderFromNote(af) - ) { - return false; - } - const { extension: target } = af; - // if list is empty, filter nothing - if (list.length === 0) return true; - else if (this.settings.blacklist) return !list.includes(target); - else return list.includes(target); - } else return false; - }; - } -} diff --git a/src/folder-count.ts b/src/folder-count.ts index 3a97f28..85d33b5 100644 --- a/src/folder-count.ts +++ b/src/folder-count.ts @@ -1,14 +1,7 @@ import './styles/folder-count.css'; -import FileExplorerNoteCount from 'fec-main'; -import { - AbstractFileFilter, - getParentPath, - isFolder, - isParent, - iterateItems, - withSubfolderClass, -} from 'misc'; +import FileExplorerNoteCount from 'main'; +import { AbstractFileFilter, getParentPath, isFolder, isParent, iterateItems, withSubfolderClass } from 'misc'; import { AFItem, FolderItem, TFolder } from 'obsidian'; const countFolderChildren = (folder: TFolder, filter: AbstractFileFilter) => { @@ -25,16 +18,14 @@ const filterParent = (pathList: string[]): Set => { const list = Array.from(pathList); list.sort(); for (let i = 0; i < list.length; i++) { - if ( - i < list.length - 1 && - (list[i] === list[i + 1] || isParent(list[i], list[i + 1])) - ) { + if (i < list.length - 1 && (list[i] === list[i + 1] || isParent(list[i], list[i + 1]))) { list.shift(); i--; } } return new Set(list); }; + /** get all parents and add to set if not exist */ const getAllParents = (path: string, set: Set): void => { let parent = getParentPath(path); @@ -43,13 +34,11 @@ const getAllParents = (path: string, set: Set): void => { parent = getParentPath(parent); } }; + /** * Update folder count of target's parent */ -export const updateCount = ( - targetList: string[], - plugin: FileExplorerNoteCount, -): void => { +export const updateCount = (targetList: string[], plugin: FileExplorerNoteCount): void => { const set = filterParent(targetList); for (const path of targetList) { getAllParents(path, set); @@ -65,13 +54,30 @@ export const updateCount = ( if (!fileExplorer.fileItems[path]) continue; setCount(fileExplorer.fileItems[path] as FolderItem, fileFilter); } + // Update root separately + if (plugin.rootFolderEl && plugin.settings.addRootFolder) { + setupRootCount(plugin); + } // empty waitingList targetList.length = 0; }; +const setupRootCount = (plugin: FileExplorerNoteCount) => { + if (plugin.rootFolderEl) { + let rootFolderElChildren = plugin.rootFolderEl.children; + if (rootFolderElChildren && rootFolderElChildren.length > 0) { + let totalCount = countFolderChildren(plugin.app.vault.getAbstractFileByPath('/') as TFolder, plugin.fileFilter); + rootFolderElChildren[0].setAttr('data-count', totalCount.toString()); + } + } +}; + export const setupCount = (plugin: FileExplorerNoteCount, revert = false) => { if (!plugin.fileExplorer) throw new Error('fileExplorer not found'); - + // For each setup, first setup the root folder + plugin.setupRootFolder(); + setupRootCount(plugin); + // Iterate other items and include new counts iterateItems(plugin.fileExplorer.fileItems, (item: AFItem) => { if (!isFolder(item)) return; if (revert) removeCount(item); @@ -83,11 +89,7 @@ export const setCount = (item: FolderItem, filter: AbstractFileFilter) => { // if (item.file.isRoot()) return; const count = countFolderChildren(item.file, filter); item.selfEl.dataset['count'] = count.toString(); - item.selfEl.toggleClass( - withSubfolderClass, - Array.isArray(item.file.children) && - item.file.children.some((af) => af instanceof TFolder), - ); + item.selfEl.toggleClass(withSubfolderClass, Array.isArray(item.file.children) && item.file.children.some((af) => af instanceof TFolder)); }; const removeCount = (item: FolderItem) => { diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..d05a55e --- /dev/null +++ b/src/main.ts @@ -0,0 +1,120 @@ +import './styles/patch.css'; + +import { AbstractFileFilter, showAllNumbersClass, withSubfolderClass, doWithFileExplorer } from 'misc'; +import { around } from 'monkey-around'; +import { FileExplorer, Plugin, TFile } from 'obsidian'; +import { VaultHandler } from 'vault-handler'; + +import { setupCount } from './folder-count'; +import { DEFAULT_SETTINGS, FENoteCountSettingTab } from './settings'; + +export default class FileExplorerNoteCount extends Plugin { + settings = DEFAULT_SETTINGS; + fileExplorer?: FileExplorer; + vaultHandler = new VaultHandler(this); + rootFolderEl: Element | null = null; + explorerNavHeaderSelector: string = '.workspace-leaf-content[data-type="file-explorer"] .nav-header'; + rootFolderClassName: string = 'oz-explorer-root-folder'; + + async onload() { + console.log('loading FileExplorerNoteCount'); + this.addSettingTab(new FENoteCountSettingTab(this.app, this)); + await this.loadSettings(); + this.app.workspace.onLayoutReady(this.initialize); + } + + onunload() { + console.log('unloading FileExplorerNoteCount'); + this.initialize(true); + } + + async loadSettings() { + this.settings = { ...this.settings, ...(await this.loadData()) }; + } + + async saveSettings() { + await this.saveData(this.settings); + } + + initialize = (revert = false) => { + let plugin = this; + // First Check if the root folder exists + let explorerHeaderEl = document.querySelector(`${this.explorerNavHeaderSelector} .${this.rootFolderClassName}`); + if (explorerHeaderEl) this.rootFolderEl = explorerHeaderEl; + + const getViewHandler = (revert: boolean) => (view: FileExplorer) => { + this.fileExplorer = view; + setupCount(this, revert); + this.setupRootFolder(revert); + if (!revert) { + this.registerEvent(this.app.workspace.on('css-change', this.setupRootFolder)); + this.vaultHandler.registerVaultEvent(); + if (this.settings.showAllNumbers) document.body.addClass('oz-show-all-num'); + } else { + for (const el of document.getElementsByClassName(withSubfolderClass)) { + el.removeClass(withSubfolderClass); + } + document.body.removeClass(showAllNumbersClass); + } + if (!revert) { + // when file explorer is closed (workspace changed) + // try to update fehanlder with new file explorer instance + this.register( + around(view, { + onClose: (next) => + function (this: FileExplorer) { + setTimeout(() => doWithFileExplorer(plugin, getViewHandler(false)), 1e3); + return next.apply(this); + }, + }) + ); + } + }; + doWithFileExplorer(plugin, getViewHandler(revert)); + }; + + setupRootFolder = (revert = false) => { + if (!this.fileExplorer) { + console.error('file-explorer not found'); + return; + } + const root = this.fileExplorer.fileItems['/']; + if (this.rootFolderEl && !this.settings.addRootFolder) { + this.rootFolderEl.remove(); + this.rootFolderEl = null; + } + // Check if root is provided by Obsidian (it shouldn't be in the new releases) + if (!root) { + // Get the Nav Header + let explorerHeaderEl = document.querySelector(this.explorerNavHeaderSelector); + if (!explorerHeaderEl) return; + if (!this.rootFolderEl && this.settings.addRootFolder) { + this.rootFolderEl = explorerHeaderEl.createEl('div', { + cls: ['tree-item', 'nav-folder', this.rootFolderClassName], + }); + this.rootFolderEl.innerHTML = ` +
+ +
+ `; + } + } + }; + + reloadCount() { + setupCount(this); + } + + get fileFilter(): AbstractFileFilter { + let list = this.settings.filterList; + return (af) => { + if (af instanceof TFile) { + const { extension: target } = af; + // if list is empty, filter nothing + if (list.length === 0) return true; + else if (this.settings.blacklist) return !list.includes(target); + else return list.includes(target); + } else return false; + }; + } +} diff --git a/src/misc.ts b/src/misc.ts index 9bca943..7935a53 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -1,23 +1,14 @@ -import { - AFItem, - FileExplorer, - FolderItem, - TAbstractFile, - TFolder, -} from 'obsidian'; +import FileExplorerNoteCount from 'main'; +import { AFItem, FileExplorer, FolderItem, TAbstractFile, TFolder } from 'obsidian'; import { dirname } from 'path-browserify'; export const withSubfolderClass = 'oz-with-subfolder'; export const showAllNumbersClass = 'oz-show-all-num'; export const rootHiddenClass = 'oz-root-hidden'; -export const isFolder = (item: AFItem): item is FolderItem => - (item as FolderItem).file instanceof TFolder; +export const isFolder = (item: AFItem): item is FolderItem => (item as FolderItem).file instanceof TFolder; -export const iterateItems = ( - items: FileExplorer['fileItems'], - callback: (item: AFItem) => any, -): void => { +export const iterateItems = (items: FileExplorer['fileItems'], callback: (item: AFItem) => any): void => { for (const key in items) { if (!Object.prototype.hasOwnProperty.call(items, key)) continue; callback(items[key]); @@ -50,3 +41,23 @@ export const isParent = (parent: string, child: string): boolean => { const parentTokens = parent.split('/').filter((i) => i.length); return parentTokens.every((t, i) => child.split('/')[i] === t); }; + +// Helper to play with the File Explorer (if exists) +export const doWithFileExplorer = (plugin: FileExplorerNoteCount, callback: (view: FileExplorer) => void) => { + let leaves; + let count = 0; + const tryGetView = () => { + leaves = plugin.app.workspace.getLeavesOfType('file-explorer'); + if (leaves.length === 0) { + if (count++ > 5) console.error('failed to get file-explorer'); + else { + console.log('file-explorer not found, retrying...'); + setTimeout(tryGetView, 500); + } + } else { + if (leaves.length > 1) console.warn('more then one file-explorer'); + callback(leaves[0].view as FileExplorer); + } + }; + tryGetView(); +}; diff --git a/src/settings.ts b/src/settings.ts index a0f092e..b3f8045 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,20 +1,20 @@ import { equals } from 'misc'; import { App, debounce, PluginSettingTab, Setting } from 'obsidian'; -import FileExplorerNoteCount from './fec-main'; +import FileExplorerNoteCount from './main'; export interface FENoteCountSettings { showAllNumbers: boolean; filterList: string[]; blacklist: boolean; - filterFolderNote: boolean; + addRootFolder: boolean; } export const DEFAULT_SETTINGS: FENoteCountSettings = { showAllNumbers: false, filterList: ['md'], blacklist: false, - filterFolderNote: true, + addRootFolder: false, }; export class FENoteCountSettingTab extends PluginSettingTab { @@ -27,10 +27,7 @@ export class FENoteCountSettingTab extends PluginSettingTab { get showOnlyNoteValue(): boolean { const { settings } = this.plugin; - return ( - settings.blacklist === DEFAULT_SETTINGS.blacklist && - equals(settings.filterList, DEFAULT_SETTINGS.filterList) - ); + return settings.blacklist === DEFAULT_SETTINGS.blacklist && equals(settings.filterList, DEFAULT_SETTINGS.filterList); } set showOnlyNoteValue(value: boolean) { @@ -53,66 +50,53 @@ export class FENoteCountSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Show All Numbers') - .setDesc( - 'Turn on this option if you want to see the number of notes even after you expand the collapsed folders', - ) + .setDesc('Turn on this option if you want to see the number of notes even after you expand the collapsed folders') .addToggle((toggle) => - toggle - .setValue(this.plugin.settings.showAllNumbers) - .onChange((value) => { - document.body.toggleClass('oz-show-all-num', value); - this.plugin.settings.showAllNumbers = value; - this.plugin.saveSettings(); - }), + toggle.setValue(this.plugin.settings.showAllNumbers).onChange((value) => { + document.body.toggleClass('oz-show-all-num', value); + this.plugin.settings.showAllNumbers = value; + this.plugin.saveSettings(); + }) ); + new Setting(containerEl) - .setName('Exclude Folder Note from Counts') + .setName('Add Root Folder') .setDesc( - createFragment((frag) => { - frag.appendText('Only work with'); - frag.createEl('a', { - href: 'https://github.com/aidenlx/folder-note-core', - text: 'Folder Note Core', - }); - frag.appendText(' Installed and Enabled'); - }), + 'By default, there is no root folder provided by Obsidian. It is moved to drop-down menu to switch between vaults. ' + + 'Enable this option if you want to see root folder and its count in the file explorer' ) .addToggle((toggle) => - toggle - .setValue(this.plugin.settings.filterFolderNote) - .onChange((value) => { - this.plugin.settings.filterFolderNote = value; - this.plugin.saveSettings(); - }), + toggle.setValue(this.plugin.settings.addRootFolder).onChange((value) => { + this.plugin.settings.addRootFolder = value; + this.plugin.saveSettings(); + this.plugin.reloadCount(); + }) ); + this.filterOpt(); } filterOpt(): void { new Setting(this.containerEl) .setName('Show Only Markdown Notes') - .setDesc( - 'Turn off this option to choose file that should be counted', - ) + .setDesc('Turn off this option to choose file that should be counted') .addToggle((toggle) => toggle.setValue(this.showOnlyNoteValue).onChange((value) => { this.showOnlyNoteValue = value; this.plugin.reloadCount(); this.plugin.saveSettings(); this.display(); - }), + }) ); if (!this.showOnlyNoteValue) { new Setting(this.containerEl) .setName('Filter List') .setDesc( createFragment((descEl) => { - descEl.appendText( - 'Extension list to include/exclude file during counting', - ); + descEl.appendText('Extension list to include/exclude file during counting'); descEl.appendChild(document.createElement('br')); descEl.appendText('Separated by comma'); - }), + }) ) .addTextArea((text) => { const onChange = async (value: string) => { @@ -121,28 +105,20 @@ export class FENoteCountSettingTab extends PluginSettingTab { this.plugin.reloadCount(); await this.plugin.saveSettings(); }; - text.setPlaceholder( - 'Leave it empty to count all types of files', - ); - text.setValue( - this.plugin.settings.filterList.join(', '), - ).onChange(debounce(onChange, 500, true)); + text.setPlaceholder('Leave it empty to count all types of files'); + text.setValue(this.plugin.settings.filterList.join(', ')).onChange(debounce(onChange, 500, true)); text.inputEl.rows = 2; text.inputEl.cols = 25; }); new Setting(this.containerEl) .setName('Enable Blacklist') - .setDesc( - 'Turn on this option to use Filter List to exclude files', - ) + .setDesc('Turn on this option to use Filter List to exclude files') .addToggle((toggle) => - toggle - .setValue(this.plugin.settings.blacklist) - .onChange((value) => { - this.plugin.settings.blacklist = value; - this.plugin.reloadCount(); - this.plugin.saveSettings(); - }), + toggle.setValue(this.plugin.settings.blacklist).onChange((value) => { + this.plugin.settings.blacklist = value; + this.plugin.reloadCount(); + this.plugin.saveSettings(); + }) ); } } diff --git a/src/styles/folder-count.css b/src/styles/folder-count.css index bff7e22..9201e4b 100644 --- a/src/styles/folder-count.css +++ b/src/styles/folder-count.css @@ -9,16 +9,18 @@ /* background-color: var(--background-secondary-alt); */ transition: opacity 100ms ease-in-out; } -.nav-folder-title.oz-root-hidden[data-count]::after { - display: none; + +.oz-explorer-root-nav-folder-title { + display: flex; } -body:not(.oz-show-all-num) - .nav-folder:not(.is-collapsed) - > .nav-folder-title.oz-with-subfolder[data-count]:not([data-path='/'])::after { - opacity: 0; +.oz-explorer-root-nav-folder-title[data-count]::after { + content: attr(data-count); + margin-right: 4px; + font-size: calc(100% * 0.8); + display: inline-block; } -.nav-folder-title[data-count='0']::after { - display: none; +body:not(.oz-show-all-num) .nav-folder:not(.is-collapsed) > .nav-folder-title.oz-with-subfolder[data-count]:not([data-path='/'])::after { + opacity: 0; } diff --git a/src/styles/patch.css b/src/styles/patch.css index c6c1d53..e33f171 100644 --- a/src/styles/patch.css +++ b/src/styles/patch.css @@ -1,3 +1,7 @@ .nav-folder-title-content { flex-grow: 1; } + +.oz-explorer-root-folder { + margin-top: 15px; +} diff --git a/src/vault-handler.ts b/src/vault-handler.ts index e40460c..90164cf 100644 --- a/src/vault-handler.ts +++ b/src/vault-handler.ts @@ -1,4 +1,4 @@ -import FileExplorerNoteCount from 'fec-main'; +import FileExplorerNoteCount from 'main'; import { updateCount } from 'folder-count'; import { getParentPath } from 'misc'; import { App, debounce, TAbstractFile, Vault } from 'obsidian'; @@ -16,11 +16,7 @@ export class VaultHandler { this.plugin = plugin; } - update = debounce( - () => updateCount(this.waitingList, this.plugin), - 500, - true, - ); + update = debounce(() => updateCount(this.waitingList, this.plugin), 500, true); handler = (...args: (string | TAbstractFile)[]) => { for (const arg of args) { diff --git a/styles.css b/styles.css index 6722b7a..bf69502 100644 --- a/styles.css +++ b/styles.css @@ -1,3 +1,11 @@ +.nav-folder-title-content { + flex-grow: 1; +} + +.oz-explorer-root-folder { + margin-top: 15px; +} + .nav-folder-title[data-count]::after { content: attr(data-count); display: inline-block; @@ -9,20 +17,18 @@ /* background-color: var(--background-secondary-alt); */ transition: opacity 100ms ease-in-out; } -.nav-folder-title.oz-root-hidden[data-count]::after { - display: none; -} -body:not(.oz-show-all-num) - .nav-folder:not(.is-collapsed) - > .nav-folder-title.oz-with-subfolder[data-count]:not([data-path='/'])::after { - opacity: 0; +.oz-explorer-root-nav-folder-title { + display: flex; } -.nav-folder-title[data-count='0']::after { - display: none; +.oz-explorer-root-nav-folder-title[data-count]::after { + content: attr(data-count); + margin-right: 4px; + font-size: calc(100% * 0.8); + display: inline-block; } -.nav-folder-title-content { - flex-grow: 1; +body:not(.oz-show-all-num) .nav-folder:not(.is-collapsed) > .nav-folder-title.oz-with-subfolder[data-count]:not([data-path='/'])::after { + opacity: 0; } diff --git a/tsconfig.json b/tsconfig.json index 8b8e7de..62d1467 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,9 @@ { "compilerOptions": { "baseUrl": "src", + "isolatedModules": true, "outDir": "", + "esModuleInterop": true, "inlineSourceMap": true, "inlineSources": true, "module": "ESNext", @@ -14,5 +16,6 @@ "allowSyntheticDefaultImports": true, "lib": ["dom", "es5", "scripthost", "ES2020", "DOM.Iterable"] }, - "include": ["src/**/*.ts"] + "include": ["**/*.ts", "**/*.tsx"], + "exclude": [] }