/*
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, {
CustomFileExtensions: () => CustomFileExtensions,
default: () => main_default
});
module.exports = __toCommonJS(main_exports);
var import_obsidian3 = require("obsidian");
// src/settings.ts
var import_obsidian = require("obsidian");
var _DEFAULT_TYPES = {
"markdown": [
"",
"md",
"txt",
"js",
"css",
"ts",
"jsx",
"tsx",
"yaml",
"yml",
"sass",
"scss",
"tex",
"json",
"html"
]
};
var DEFAULT_SETTINGS = {
types: _DEFAULT_TYPES,
configIsValid: true,
errors: {},
allowMdOverride: false,
mobileSettings: {
enabled: false,
configIsValid: true,
types: _DEFAULT_TYPES
}
};
var CustomFileExtensionsSettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this._defaults = void 0;
this.plugin = plugin;
}
display() {
const { containerEl } = this;
const example = JSON.stringify(DEFAULT_SETTINGS.types, null, 2);
containerEl.empty();
containerEl.createEl("h2", { text: "Custom File Extensions Settings" });
this._config = new import_obsidian.Setting(containerEl).setName("Config").setDesc("Valid entry is a JSON object who's property keys are view types and values are arrays of the file types to assign to that view.");
let exampleText = document.createElement("div");
exampleText.style.fontSize = "80%";
exampleText.style.margin = "10px";
exampleText.innerHTML = `Ex: ${example}`;
this._config.nameEl.parentElement.appendChild(exampleText);
let configTextArea = new import_obsidian.TextAreaComponent(containerEl).setPlaceholder(example).setValue(JSON.stringify(this.plugin.settings.types, null, 2)).onChange(async (value) => {
let parsed = null;
let next = {
...this.plugin.settings
};
try {
parsed = JSON.parse(value);
next.configIsValid = true;
next.types = parsed;
} catch (e) {
next.configIsValid = false;
}
this._updateConfigValidity(configTextArea, this.plugin.settings.configIsValid, next.configIsValid);
await this.plugin.updateSettings(next);
this._updateErrors();
this._updateList();
this._updateProfile();
});
configTextArea.inputEl.style.width = "100%";
configTextArea.inputEl.style.height = "150px";
configTextArea.inputEl.style.minHeight = "100px";
this._mobileConfig = new import_obsidian.Setting(containerEl).setName("Mobile Specific Config").setDesc("If enabled: the config settings below will be used on mobile devices, and the above settings.").addToggle((toggle) => {
toggle.setValue(this.plugin.settings.mobileSettings.enabled).onChange(async (value) => {
let next = {
...this.plugin.settings,
mobileSettings: {
...this.plugin.settings.mobileSettings,
enabled: value
}
};
await this.plugin.updateSettings(next);
this._updateMobileConfigVisible(mobileConfigField, value);
this._updateErrors();
this._updateList();
this._updateProfile();
});
return toggle;
});
let mobileConfigField = new import_obsidian.TextAreaComponent(containerEl).setPlaceholder(example).setValue(this.plugin.settings.mobileSettings.types ? JSON.stringify(this.plugin.settings.mobileSettings.types, null, 2) : "").onChange(async (value) => {
let next = {
...this.plugin.settings,
mobileSettings: {
...this.plugin.settings.mobileSettings,
types: void 0
}
};
if (value !== "" && value !== null && value !== void 0) {
try {
let parsed = JSON.parse(value);
next.mobileSettings.configIsValid = true;
next.mobileSettings.types = parsed;
} catch (e) {
next.mobileSettings.configIsValid = false;
}
}
this._updateConfigValidity(mobileConfigField, this.plugin.settings.mobileSettings.configIsValid, next.mobileSettings.configIsValid);
await this.plugin.updateSettings(next);
this._updateErrors();
this._updateList();
this._updateProfile();
});
mobileConfigField.inputEl.style.width = "100%";
mobileConfigField.inputEl.style.height = "150px";
mobileConfigField.inputEl.style.minHeight = "100px";
this._updateMobileConfigVisible(mobileConfigField, this.plugin.settings.mobileSettings.enabled);
new import_obsidian.Setting(containerEl).setName("Allow Override Of .md Extension").setDesc("If enabled: the .md extension will be allowed to override the default markdown view type. This is disabled by default to prevent unexpected behavior.").addToggle((toggle) => {
toggle.setValue(this.plugin.settings.allowMdOverride).onChange(async (value) => {
let next = {
...this.plugin.settings,
allowMdOverride: value
};
await this.plugin.updateSettings(next);
});
return toggle;
});
containerEl.createEl("h3", { text: "Errors" });
this._errors = containerEl.createEl("p", { text: "None" });
this._errors.style.whiteSpace = "pre-line";
containerEl.createEl("h3", { text: "Active View Types and Extensions" });
this._views = containerEl.createEl("p");
this._views.style.whiteSpace = "pre-line";
this._updateErrors();
this._updateList();
this._updateProfile();
}
_updateMobileConfigVisible(mobileConfigField, mobileSettingsEnabled) {
mobileConfigField.inputEl.style.display = mobileSettingsEnabled ? "block" : "none";
}
_updateConfigValidity(text, prevWasValid, nextIsValid) {
if (prevWasValid !== nextIsValid) {
if (prevWasValid) {
if (!this._defaults) {
this._defaults = {
color: text.inputEl.style.color,
borderColor: text.inputEl.style.borderColor,
borderWidth: text.inputEl.style.borderWidth
};
}
text.inputEl.style.color = "var(--text-error)";
text.inputEl.style.borderColor = "var(--background-modifier-error-rgb)";
text.inputEl.style.borderWidth = "3px";
} else if (this._defaults) {
text.inputEl.style.color = this._defaults.color;
text.inputEl.style.borderColor = this._defaults.borderColor;
text.inputEl.style.borderWidth = this._defaults.borderWidth;
}
}
}
_updateErrors() {
if (Object.keys(this.plugin.settings.errors).length === 0) {
this._errors.innerHTML = `None`;
this._errors.style.color = "green";
} else {
this._errors.innerHTML = `Errors:
${ext}` : `"" (extensionless)`).join(", ")}` : ``}