Skip to content

Commit

Permalink
Merge pull request #77 from hdykokd/improve-reactivity
Browse files Browse the repository at this point in the history
feat: improve reactivity
  • Loading branch information
hdykokd authored Apr 17, 2024
2 parents 80b5c4f + 9a35233 commit 5606c3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/components/Tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
} as const;
let plugin: VerticalTabsView;
let leaves: Leaf[];
let activeLeafId: string;
$: settings = plugin.settings
$: tabIconRules = settings.tabIconRules.slice().sort((a, b) => b.priority - a.priority)
let leaves: Leaf[] = []
$: leaves = leaves
let activeLeafId: string = "";
$: activeLeafId = activeLeafId
store.plugin.subscribe((v) => {
plugin = v;
});
Expand All @@ -45,12 +52,6 @@
export let viewContentId: string;
export let updateView: Function;
let tabIconRules: TabIconRule[] = [];
const getTabIconRules = () => {
return plugin.settings.tabIconRules.sort((a, b) => b.priority - a.priority);
};
$: tabIconRules = getTabIconRules();
const regexCompileCache: Record<string, RegExp> = {};
Expand Down Expand Up @@ -202,7 +203,8 @@
const selector = `li[data-leaf-id="${leaf.id}"] .${VIEW_LIST_ITEM_TAB_ICON_CLASS}`;
const tabIcon = document.querySelector(selector) as HTMLElement;
if (!tabIcon) return;
if (!plugin.settings.showTabIcon) {
if (!settings.showTabIcon) {
tabIcon.addClass('_hidden');
return;
} else {
Expand All @@ -218,9 +220,9 @@
if (matchedConfig) {
// override
setIcon(tabIcon, matchedConfig.icon);
} else if (plugin.settings.defaultTabIcon) {
} else if (settings.defaultTabIcon) {
// set default
setIcon(tabIcon, plugin.settings.defaultTabIcon);
setIcon(tabIcon, settings.defaultTabIcon);
} else if (leaf.getViewState().type === 'markdown') {
// remove
setIcon(tabIcon, '');
Expand Down Expand Up @@ -381,7 +383,7 @@
}}
>
<div class="vertical-tabs-view-list-item-left-container">
{#if plugin.settings.showCloseIcon}
{#if settings.showCloseIcon}
<div
class="vertical-tabs-view-list-item-close-btn vertical-tabs-view-list-item-icon"
on:click={(e) => handleClickClose(e, leaf)}
Expand All @@ -391,21 +393,21 @@
{/if}
<div class="vertical-tabs-view-list-item-tab-icon vertical-tabs-view-list-item-icon" />
<div class="vertical-tabs-view-list-item-name-container">
{#if plugin.settings.showDirectory}
{#if settings.showDirectory}
<span class="vertical-tabs-view-list-item-dirname">{getDirname(leaf)}</span>
{/if}
<span class="vertical-tabs-view-list-item-title">{getFilename(leaf)}</span>
</div>
</div>
<div class="vertical-tabs-view-list-item-right-container">
{#if plugin.settings.showPinIconIfNotPinned && !leaf.pinned}
{#if settings.showPinIconIfNotPinned && !leaf.pinned}
<div
class="vertical-tabs-view-list-item-icon vertical-tabs-view-list-item-pin-btn vertical-tabs-view-list-item-pin-btn-pin"
on:click={(e) => handleClickPin(e, leaf)}
>
<Pin />
</div>
{:else if plugin.settings.showPinnedIcon && leaf.pinned}
{:else if settings.showPinnedIcon && leaf.pinned}
<div
class="vertical-tabs-view-list-item-icon vertical-tabs-view-list-item-icon-pinned vertical-tabs-view-list-item-pin-btn vertical-tabs-view-list-item-pin-btn-pin"
on:click={(e) => handleClickPinOff(e, leaf)}
Expand Down
2 changes: 2 additions & 0 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class VerticalTabsViewView extends ItemView {
const state = leaf.getViewState();
if (state.type === VIEW_TYPE_VERTICAL_TABS) return;
store.activeLeafId.set(leaf.id);
this.updateView();
}),
);
}
Expand Down Expand Up @@ -116,6 +117,7 @@ export class VerticalTabsViewView extends ItemView {
}

updateView() {
store.plugin.set(this.plugin);
const leaves = this.getSortedLeaves();
leaves.forEach((l) => {
l.on('pinned-change', () => {
Expand Down

0 comments on commit 5606c3a

Please sign in to comment.