generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #43 Use new tree api for collapse and expand
There were internal breaking changes to the Obsidian api. Updated each provider with its current state. Closes: #43
- Loading branch information
Showing
7 changed files
with
99 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = { | ||
env: { | ||
es2021: true, | ||
node: true | ||
}, | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true | ||
}, | ||
files: ['.eslintrc.{js,cjs}'], | ||
parserOptions: { | ||
sourceType: 'script' | ||
} | ||
} | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module' | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
rules: { | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
args: 'all', | ||
argsIgnorePattern: '^_', | ||
caughtErrors: 'all', | ||
caughtErrorsIgnorePattern: '^_', | ||
destructuredArrayIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
ignoreRestSiblings: true | ||
} | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
import { WorkspaceLeaf } from 'obsidian'; | ||
import { Command, WorkspaceLeaf } from 'obsidian'; | ||
import { ProviderType } from '../constants'; | ||
import { ProviderBase } from './base'; | ||
|
||
export class TagPaneProvider extends ProviderBase { | ||
providerType: ProviderType = ProviderType.TagPane; | ||
displayName = 'Tag pane'; | ||
protected leafType = 'tag'; | ||
protected readonly collapseCommandName = | ||
'Collapse open tags in all tag explorers'; | ||
protected readonly expandCommandName = | ||
'Expand closed tags in all tag explorers'; | ||
protected readonly collapseCommandName = 'Not available'; | ||
protected readonly expandCommandName = 'Not available'; | ||
protected readonly toggleCommandName = 'Toggle collapse in all tag explorers'; | ||
|
||
protected override get commands(): Command[] { | ||
return [this.toggleCommand]; | ||
} | ||
|
||
public override toggleCollapse(singleLeaf?: WorkspaceLeaf): void { | ||
const leaves = singleLeaf ? [singleLeaf] : this.leaves; | ||
for (const leaf of leaves) { | ||
leaf.view.collapseOrExpandAllEl?.click(); | ||
if (!leaf.view.collapseOrExpandAllEl) { | ||
console.error(`No collapse element found on ${this.leafType} view.`); | ||
return; | ||
} | ||
leaf.view.collapseOrExpandAllEl.click(); | ||
} | ||
} | ||
|
||
public override collapseAll(_?: WorkspaceLeaf | null): void { | ||
// Not available | ||
} | ||
|
||
public override expandAll(_?: WorkspaceLeaf | null): void { | ||
// Not available | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
// eslint-disable-next-line - Need at least one import so this compiles. | ||
import { View } from 'obsidian'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import type { View } from 'obsidian'; | ||
declare module 'obsidian' { | ||
interface View { | ||
toggleCollapseAll: () => void; | ||
setCollapseAll: (collapse: boolean) => void; | ||
isAllCollapsed: boolean; | ||
collapseOrExpandAllEl: HTMLDivElement; | ||
tree?: { | ||
toggleCollapseAll?: () => void; | ||
setCollapseAll?: (collapse: boolean) => void; | ||
isAllCollapsed?: boolean; | ||
}; | ||
toggleCollapseAll?: () => void; | ||
setCollapseAll?: (collapse: boolean) => void; | ||
isAllCollapsed?: boolean; | ||
collapseOrExpandAllEl?: HTMLDivElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters