+
${this.app.vault.getName()}
+
+ `;
+ }
+ }
+ };
+
+ 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": []
}