/*
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
*/
'use strict';
var obsidian = require('obsidian');
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function setAttributes(element, attributes) {
for (let key in attributes) {
element.setAttribute(key, attributes[key]);
}
}
class CreateSnippetModal extends obsidian.Modal {
constructor(app, plugin) {
super(app);
this.app = app;
this.plugin = plugin;
this.onOpen = () => this.display(true);
}
display(focus) {
return __awaiter(this, void 0, void 0, function* () {
const { contentEl } = this;
const customCss = this.app.customCss;
contentEl.empty();
contentEl.setAttribute("style", "margin-top: 0px");
const title = document.createElement("h1");
title.setText("Create a CSS Snippet");
contentEl.appendChild(title);
const fileTitleSetting = new obsidian.Setting(contentEl);
const fileTitleValue = new obsidian.TextComponent(fileTitleSetting.controlEl);
fileTitleSetting
.setName("CSS Snippet Title")
.setDesc("Write the title for this CSS snippet file.");
const cssStylesSetting = new obsidian.Setting(contentEl);
// avoiding having to reference this specific modal - add style in code
cssStylesSetting.settingEl.setAttribute("style", "display: grid; grid-template-columns: 1fr;");
const cssStylesValue = new obsidian.TextAreaComponent(cssStylesSetting.controlEl);
setAttributes(cssStylesValue.inputEl, {
style: "margin-top: 12px; width: 100%; height: 32vh;",
class: "ms-css-editor",
});
cssStylesSetting
.setName("CSS Snippet Styles")
.setDesc("Add in styling for this CSS snippet file.");
cssStylesValue.setValue(this.plugin.settings.stylingTemplate);
const doAdd = () => __awaiter(this, void 0, void 0, function* () {
let fileName = fileTitleValue.getValue();
let fileContents = cssStylesValue.getValue();
let snippetPath = customCss.getSnippetPath(fileName);
if (fileName) {
if (!customCss.snippets.includes(fileName)) {
yield app.vault.create(`${customCss.getSnippetsFolder()}/${fileName}.css`, fileContents);
console.log(`%c"${fileName}.css" has been created!`, "color: Violet");
if (this.plugin.settings.snippetEnabledStatus)
customCss.setCssEnabledStatus(fileName, true);
if (this.plugin.settings.openSnippetFile)
this.app.openWithDefaultApp(snippetPath);
customCss.requestLoadSnippets();
this.close();
}
else
new obsidian.Notice(`"${fileName}.css" already exists.`);
}
else
new obsidian.Notice("Missing name for file");
});
const saveButton = new obsidian.ButtonComponent(contentEl)
.setButtonText("Create Snippet")
.onClick(doAdd);
saveButton.buttonEl.addClass("wg-button");
fileTitleValue.inputEl.focus();
});
}
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}
function snippetsMenu(app, plugin, settings) {
const windowX = window.innerWidth;
const windowY = window.innerHeight;
const menuExists = document.querySelector(".menu.MySnippets-statusbar-menu");
if (!menuExists) {
const menu = new obsidian.Menu();
menu.setUseNativeMenu(false);
const menuDom = menu.dom;
menuDom.addClass("MySnippets-statusbar-menu");
if (settings.aestheticStyle) {
menuDom.setAttribute("style", "background-color: transparent; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);");
}
const customCss = app.customCss;
const currentSnippets = customCss.snippets;
const snippetsFolder = customCss.getSnippetsFolder();
currentSnippets.forEach((snippet) => {
const snippetPath = customCss.getSnippetPath(snippet);
menu.addItem((snippetElement) => {
snippetElement.setTitle(snippet);
const snippetElementDom = snippetElement.dom;
const toggleComponent = new obsidian.ToggleComponent(snippetElementDom);
const buttonComponent = new obsidian.ButtonComponent(snippetElementDom);
function changeSnippetStatus() {
const isEnabled = customCss.enabledSnippets.has(snippet);
customCss.setCssEnabledStatus(snippet, !isEnabled);
}
toggleComponent
.setValue(customCss.enabledSnippets.has(snippet))
.onChange(changeSnippetStatus);
buttonComponent
.setIcon("ms-snippet")
.setClass("MS-OpenSnippet")
.setTooltip(`Open snippet`)
.onClick((e) => {
app.openWithDefaultApp(snippetPath);
});
snippetElement.onClick((e) => {
e.preventDefault();
e.stopImmediatePropagation();
});
});
});
menu.addSeparator();
menu.addItem((actions) => {
actions.setIcon(null);
actions.setTitle("Actions");
const actionsDom = actions.dom;
setAttributes(actions.titleEl, { style: "font-weight: 700" });
const reloadButton = new obsidian.ButtonComponent(actionsDom);
const folderButton = new obsidian.ButtonComponent(actionsDom);
const addButton = new obsidian.ButtonComponent(actionsDom);
setAttributes(reloadButton.buttonEl, { style: "margin-right: 3px" });
setAttributes(addButton.buttonEl, { style: "margin-left: 3px" });
reloadButton
.setIcon("ms-reload")
.setClass("MySnippetsButton")
.setClass("MS-Reload")
.setTooltip("Reload snippets")
.onClick((e) => {
customCss.requestLoadSnippets();
new obsidian.Notice("Snippets reloaded");
});
folderButton
.setIcon("ms-folder")
.setClass("MySnippetsButton")
.setClass("MS-Folder")
.setTooltip("Open snippets folder")
.onClick((e) => {
app.openWithDefaultApp(snippetsFolder);
});
addButton
.setIcon("ms-add")
.setClass("MySnippetsButton")
.setClass("MS-Folder")
.setTooltip("Create new snippet")
.onClick((e) => {
new CreateSnippetModal(app, plugin).open();
});
});
menu.showAtPosition({
x: windowX - 15,
y: windowY - 37,
});
}
}
const icons = {
"art-fill": ``,
"art-brush": ``,
"ms-create-file": ``,
"pantone-line": ``,
"ms-code": ``,
"ms-reload": ``,
"ms-folder": ``,
"ms-snippet": ``,
"ms-add": ``,
"ms-save": ``,
"ms-delete": ``,
"ms-css-file": ``,
};
function addIcons() {
Object.keys(icons).forEach((key) => {
obsidian.addIcon(key, icons[key]);
});
}
class MySnippetsSettingTab extends obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h1", { text: "MySnippets" });
containerEl.createEl("p", { text: "Created by " }).createEl("a", {
text: "Chetachi 👩🏽💻",
href: "https://github.com/chetachiezikeuzor",
});
containerEl.createEl("h2", { text: "Plugin Settings" });
new obsidian.Setting(containerEl)
.setName("Glass menu effect")
.setDesc("Choose to change the background from the secondary background color of your theme to a glass background.")
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.aestheticStyle)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.aestheticStyle = value;
this.plugin.saveSettings();
}));
});
new obsidian.Setting(containerEl)
.setName("Auto open new snippet")
.setDesc("Choose whether or not to open CSS snippet files immeditaley after creating them. It will open in your default app.")
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.openSnippetFile)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.openSnippetFile = value;
this.plugin.saveSettings();
}));
});
new obsidian.Setting(containerEl)
.setName("Set new snippet status")
.setDesc("Choose whether or not to have newly created CSS snippet files toggled on automatically upon creation.")
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.snippetEnabledStatus)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.snippetEnabledStatus = value;
this.plugin.saveSettings();
}));
});
const stylingTemplateSetting = new obsidian.Setting(containerEl);
stylingTemplateSetting.settingEl.setAttribute("style", "display: grid; grid-template-columns: 1fr;");
stylingTemplateSetting
.setName("CSS snippet template")
.setDesc("Set default CSS styling as a template for new CSS files you choose to create.");
const stylingTemplateContent = new obsidian.TextAreaComponent(stylingTemplateSetting.controlEl);
setAttributes(stylingTemplateContent.inputEl, {
style: "margin-top: 12px; width: 100%; height: 32vh;",
class: "ms-css-editor",
});
stylingTemplateContent
.setValue(this.plugin.settings.stylingTemplate)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
this.plugin.settings.stylingTemplate = value;
this.plugin.saveSettings();
}));
const msDonationDiv = containerEl.createEl("div", {
cls: "msDonationSection",
});
const donateText = createEl("p");
donateText.appendText("If you like this Plugin and are considering donating to support continued development, use the buttons below!");
msDonationDiv.appendChild(donateText);
msDonationDiv.appendChild(paypalButton("https://paypal.me/chelseaezikeuzor"));
msDonationDiv.appendChild(buyMeACoffeeButton("https://www.buymeacoffee.com/chetachi"));
msDonationDiv.appendChild(kofiButton("https://ko-fi.com/chetachi"));
}
}
const buyMeACoffeeButton = (link) => {
const a = createEl("a");
a.setAttribute("href", link);
a.addClass("buymeacoffee-chetachi-img");
a.innerHTML = `
`;
return a;
};
const paypalButton = (link) => {
const a = createEl("a");
a.setAttribute("href", link);
a.addClass("buymeacoffee-chetachi-img");
a.innerHTML = ``;
return a;
};
const kofiButton = (link) => {
const a = createEl("a");
a.setAttribute("href", link);
a.addClass("buymeacoffee-chetachi-img");
a.innerHTML = `
`;
return a;
};
const DEFAULT_SETTINGS = {
aestheticStyle: false,
snippetViewPosition: "left",
openSnippetFile: true,
stylingTemplate: "",
snippetEnabledStatus: false,
};
class MySnippetsPlugin extends obsidian.Plugin {
onload() {
return __awaiter(this, void 0, void 0, function* () {
console.log(`MySnippets v${this.manifest.version} loaded`);
addIcons();
yield this.loadSettings();
this.addSettingTab(new MySnippetsSettingTab(this.app, this));
this.app.workspace.onLayoutReady(() => {
setTimeout(() => {
this.setupSnippetsStatusBarIcon();
});
});
});
}
setupSnippetsStatusBarIcon() {
this.statusBarIcon = this.addStatusBarItem();
this.statusBarIcon.addClass("MiniSettings-statusbar-button");
this.statusBarIcon.addClass("mod-clickable");
setAttributes(this.statusBarIcon, {
"aria-label": "Configure Snippets",
"aria-label-position": "top",
});
obsidian.setIcon(this.statusBarIcon, "pantone-line");
this.statusBarIcon.addEventListener("click", () => {
snippetsMenu(this.app, this, this.settings);
});
this.addCommand({
id: `open-snippets-menu`,
name: `Open snippets in status bar`,
icon: `pantone-line`,
callback: () => __awaiter(this, void 0, void 0, function* () {
snippetsMenu(this.app, this, this.settings);
}),
});
this.addCommand({
id: `open-snippets-create`,
name: `Create new CSS snippet`,
icon: `ms-css-file`,
callback: () => __awaiter(this, void 0, void 0, function* () {
new CreateSnippetModal(this.app, this).open();
}),
});
}
onunload() {
console.log("MySnippets unloaded");
}
loadSettings() {
return __awaiter(this, void 0, void 0, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __awaiter(this, void 0, void 0, function* () {
yield this.saveData(this.settings);
});
}
}
module.exports = MySnippetsPlugin;
/* nosourcemap */