Created
October 28, 2023 01:18
-
-
Save gerald-kim/ae1266112fbd75619c5eb56b6ab6e08f to your computer and use it in GitHub Desktop.
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 IS A GENERATED/BUNDLED FILE BY ESBUILD | |
if you want to view the source, please visit the github repository of this plugin | |
*/ | |
var __defProp = Object.defineProperty; | |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | |
var __getOwnPropNames = Object.getOwnPropertyNames; | |
var __hasOwnProp = Object.prototype.hasOwnProperty; | |
var __export = (target, all) => { | |
for (var name in all) | |
__defProp(target, name, { get: all[name], enumerable: true }); | |
}; | |
var __copyProps = (to, from, except, desc) => { | |
if (from && typeof from === "object" || typeof from === "function") { | |
for (let key of __getOwnPropNames(from)) | |
if (!__hasOwnProp.call(to, key) && key !== except) | |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | |
} | |
return to; | |
}; | |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | |
// src/main.ts | |
var main_exports = {}; | |
__export(main_exports, { | |
default: () => NoTabsPlugin | |
}); | |
module.exports = __toCommonJS(main_exports); | |
var import_obsidian2 = require("obsidian"); | |
// src/settings.ts | |
var import_obsidian = require("obsidian"); | |
var SettingsTab = class extends import_obsidian.PluginSettingTab { | |
constructor(app, plugin) { | |
super(app, plugin); | |
this.plugin = plugin; | |
} | |
display() { | |
const { containerEl } = this; | |
containerEl.empty(); | |
containerEl.createEl("h2", { text: "NoTabs Settings" }); | |
new import_obsidian.Setting(containerEl).setName("Strict Mode").setDesc( | |
"Warning: Strict Mode will close all tabs that are not active or pinned" | |
).addToggle( | |
(toggle) => toggle.setValue(this.plugin.data.settings.strictMode).onChange(async (value) => { | |
this.plugin.data.settings.strictMode = value; | |
await this.plugin.saveData(); | |
}) | |
); | |
} | |
}; | |
// src/main.ts | |
var DEFAULT_SETTINGS = { | |
strictMode: false | |
}; | |
var DEFAULT_DATA = { | |
settings: DEFAULT_SETTINGS | |
}; | |
var NoTabsPlugin = class extends import_obsidian2.Plugin { | |
constructor() { | |
super(...arguments); | |
this.activeTab = null; | |
this.newFile = false; | |
} | |
async onload() { | |
await this.loadData(); | |
this.registerEvent( | |
this.app.vault.on("create", () => { | |
if (this.data.settings.strictMode) | |
return; | |
this.activeTab = this.app.workspace.getMostRecentLeaf(); | |
if (!this.activeTab) | |
return; | |
const { pinned, type } = this.activeTab.getViewState(); | |
if (pinned) | |
return; | |
if (type === "empty") | |
return; | |
this.newFile = true; | |
}) | |
); | |
this.registerEvent( | |
this.app.workspace.on("file-open", () => { | |
var _a; | |
if (this.data.settings.strictMode) | |
return; | |
if (!this.newFile) | |
return; | |
this.newFile = false; | |
(_a = this.activeTab) == null ? void 0 : _a.detach(); | |
this.activeTab = this.app.workspace.getMostRecentLeaf(); | |
}) | |
); | |
this.registerEvent( | |
this.app.workspace.on( | |
"active-leaf-change", | |
(activeLeaf) => { | |
console.log("active-leaf-change"); | |
const content = activeLeaf.view.data; | |
if (!content || content.trim() === "") { | |
console.log("This is a new document!"); | |
} else if (activeLeaf.view instanceof import_obsidian2.MarkdownView) { | |
const view = activeLeaf.getViewState(); | |
view.state.mode = 'preview'; | |
activeLeaf.setViewState(view); | |
} | |
if (!this.data.settings.strictMode) | |
return; | |
if (activeLeaf.getViewState().pinned) | |
return; | |
const { type } = activeLeaf.getViewState(); | |
if (type === "empty" || type === "markdown") { | |
activeLeaf.parent.children.forEach( | |
(leaf) => { | |
if ( | |
// @ts-ignore | |
leaf.id !== activeLeaf.id && !leaf.getViewState().pinned | |
) { | |
leaf.detach(); | |
} | |
} | |
); | |
} | |
} | |
) | |
); | |
this.addSettingTab(new SettingsTab(this.app, this)); | |
} | |
async saveData() { | |
await super.saveData(this.data); | |
} | |
async loadData() { | |
this.data = Object.assign({}, DEFAULT_DATA, await super.loadData()); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment