mirror of
https://github.com/jackyzha0/quartz.git
synced 2026-03-24 15:05:42 -05:00
2058 lines
68 KiB
JavaScript
2058 lines
68 KiB
JavaScript
/*
|
|
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);
|
|
|
|
// main.ts
|
|
var main_exports = {};
|
|
__export(main_exports, {
|
|
default: () => PgMain
|
|
});
|
|
module.exports = __toCommonJS(main_exports);
|
|
var import_obsidian20 = require("obsidian");
|
|
|
|
// src/PluginGroupSettings.ts
|
|
var import_obsidian19 = require("obsidian");
|
|
|
|
// src/Utils/Constants.ts
|
|
var disableStartupTimeout = 25 * 1e3;
|
|
var pluginId = "obsidian-plugin-groups";
|
|
var deviceNameKey = "obsidian-plugin-groups-device-name";
|
|
var knownPluginIdsKey = "obsidian-plugin-groups-known-plugins";
|
|
|
|
// src/DataStructures/PluginGroup.ts
|
|
var import_obsidian = require("obsidian");
|
|
|
|
// src/DataStructures/PgPlugin.ts
|
|
var PgPlugin = class {
|
|
constructor(id, name) {
|
|
this.id = id;
|
|
this.name = name;
|
|
}
|
|
};
|
|
|
|
// src/Managers/PluginManager.ts
|
|
var _PluginManager = class {
|
|
static async queuePluginForEnable(plugin) {
|
|
if (this.checkPluginEnabled(plugin)) {
|
|
return false;
|
|
}
|
|
if (this.enablePluginQueue.has(plugin.id)) {
|
|
return false;
|
|
}
|
|
this.enablePluginQueue.add(plugin.id);
|
|
const enabled = await this.enablePlugin(plugin);
|
|
if (enabled) {
|
|
this.pgEnabledPlugins.add(plugin.id);
|
|
}
|
|
this.enablePluginQueue.delete(plugin.id);
|
|
return true;
|
|
}
|
|
static queueDisablePlugin(plugin) {
|
|
if (!this.checkPluginEnabled(plugin)) {
|
|
return false;
|
|
}
|
|
if (this.disablePluginQueue.has(plugin.id)) {
|
|
return;
|
|
}
|
|
this.disablePluginQueue.add(plugin.id);
|
|
this.disablePlugin(plugin);
|
|
this.pgEnabledPlugins.delete(plugin.id);
|
|
this.disablePluginQueue.delete(plugin.id);
|
|
}
|
|
static async loadNewPlugins() {
|
|
if (_PluginManager.getKnownPluginIds() === null) {
|
|
_PluginManager.setKnownPluginIds(_PluginManager.getInstalledPluginIds());
|
|
} else {
|
|
const knownPlugins = _PluginManager.getKnownPluginIds();
|
|
const installedPlugins = _PluginManager.getInstalledPluginIds();
|
|
if (!installedPlugins) {
|
|
return;
|
|
}
|
|
_PluginManager.setKnownPluginIds(installedPlugins);
|
|
installedPlugins == null ? void 0 : installedPlugins.forEach((id) => {
|
|
if (!(knownPlugins == null ? void 0 : knownPlugins.has(id))) {
|
|
Manager.getInstance().groupsMap.forEach((g) => {
|
|
if (g.autoAdd) {
|
|
const plugin = _PluginManager.getInstalledPluginFromId(id);
|
|
if (plugin) {
|
|
g.addPlugin(plugin);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
return Manager.getInstance().saveSettings();
|
|
}
|
|
}
|
|
static getKnownPluginIds() {
|
|
const ids = loadVaultLocalStorage(knownPluginIdsKey);
|
|
if (!ids) {
|
|
return null;
|
|
}
|
|
return new Set(JSON.parse(ids));
|
|
}
|
|
static setKnownPluginIds(ids) {
|
|
if (!ids) {
|
|
return;
|
|
}
|
|
const setAsString = JSON.stringify([...ids]);
|
|
saveVaultLocalStorage(knownPluginIdsKey, setAsString);
|
|
}
|
|
static getInstalledPluginIds() {
|
|
const manifests = Manager.getInstance().pluginsManifests;
|
|
const installedPlugins = /* @__PURE__ */ new Set();
|
|
for (const key in manifests) {
|
|
installedPlugins.add(key);
|
|
}
|
|
return installedPlugins;
|
|
}
|
|
static getInstalledPluginFromId(id) {
|
|
var _a;
|
|
if (!Manager.getInstance().obsidianPluginsObject) {
|
|
return null;
|
|
}
|
|
if (!((_a = Manager.getInstance().pluginsManifests) == null ? void 0 : _a[id])) {
|
|
return null;
|
|
}
|
|
return new PgPlugin(Manager.getInstance().pluginsManifests[id].id, Manager.getInstance().pluginsManifests[id].name);
|
|
}
|
|
static getAllAvailablePlugins() {
|
|
const manifests = Manager.getInstance().pluginsManifests;
|
|
const plugins = [];
|
|
for (const key in manifests) {
|
|
if (manifests[key].id === pluginId)
|
|
continue;
|
|
const info = new PgPlugin(manifests[key].id, manifests[key].name);
|
|
plugins.push(info);
|
|
}
|
|
return plugins;
|
|
}
|
|
static checkPluginEnabled(plugin) {
|
|
return Manager.getInstance().obsidianPluginsObject.enabledPlugins.has(plugin.id) || this.checkPluginEnabledFromPluginGroups(plugin);
|
|
}
|
|
static checkPluginEnabledFromPluginGroups(plugin) {
|
|
return this.pgEnabledPlugins.has(plugin.id);
|
|
}
|
|
static enablePlugin(plugin) {
|
|
return Manager.getInstance().obsidianPluginsObject.enablePlugin(plugin.id);
|
|
}
|
|
static disablePlugin(plugin) {
|
|
return Manager.getInstance().obsidianPluginsObject.disablePlugin(plugin.id);
|
|
}
|
|
};
|
|
var PluginManager = _PluginManager;
|
|
PluginManager.enablePluginQueue = /* @__PURE__ */ new Set();
|
|
PluginManager.disablePluginQueue = /* @__PURE__ */ new Set();
|
|
PluginManager.pgEnabledPlugins = /* @__PURE__ */ new Set();
|
|
|
|
// src/DataStructures/PluginGroup.ts
|
|
var PluginGroup = class {
|
|
constructor(pgData) {
|
|
this.loadAtStartup = false;
|
|
this.disableOnStartup = false;
|
|
this.delay = 0;
|
|
var _a, _b, _c, _d, _e;
|
|
this.id = pgData.id;
|
|
this.name = pgData.name;
|
|
this.assignAndLoadPlugins(pgData.plugins);
|
|
this.groupIds = (_a = pgData.groupIds) != null ? _a : [];
|
|
this.loadAtStartup = (_b = pgData.loadAtStartup) != null ? _b : false;
|
|
this.disableOnStartup = (_c = pgData.disableOnStartup) != null ? _c : false;
|
|
this.delay = (_d = pgData.delay) != null ? _d : 2;
|
|
this.generateCommands = (_e = pgData.generateCommands) != null ? _e : false;
|
|
this.assignedDevices = pgData.assignedDevices;
|
|
this.autoAdd = pgData.autoAdd;
|
|
}
|
|
groupActive() {
|
|
var _a;
|
|
if (!this.assignedDevices || this.assignedDevices.length === 0) {
|
|
return true;
|
|
}
|
|
const activeDevice = getCurrentlyActiveDevice();
|
|
if (!activeDevice) {
|
|
return true;
|
|
}
|
|
return !!((_a = this.assignedDevices) == null ? void 0 : _a.contains(activeDevice));
|
|
}
|
|
assignAndLoadPlugins(plugins) {
|
|
this.plugins = plugins != null ? plugins : [];
|
|
}
|
|
startup() {
|
|
if (!this.loadAtStartup) {
|
|
return;
|
|
}
|
|
if (this.disableOnStartup) {
|
|
setTimeout(async () => {
|
|
await this.disable();
|
|
}, this.delay * 1e3);
|
|
return;
|
|
}
|
|
setTimeout(async () => {
|
|
await this.enable();
|
|
}, this.delay * 1e3);
|
|
return;
|
|
}
|
|
async enable() {
|
|
var _a;
|
|
if (!this.groupActive()) {
|
|
return;
|
|
}
|
|
const pluginPromises = [];
|
|
for (const plugin of this.plugins) {
|
|
if (Manager.getInstance().doLoadSynchronously) {
|
|
pluginPromises.push(PluginManager.queuePluginForEnable(plugin));
|
|
} else {
|
|
await PluginManager.queuePluginForEnable(plugin);
|
|
}
|
|
}
|
|
await Promise.allSettled(pluginPromises);
|
|
for (const groupId of this.groupIds) {
|
|
await ((_a = groupFromId(groupId)) == null ? void 0 : _a.enable());
|
|
}
|
|
if (Manager.getInstance().showNoticeOnGroupLoad) {
|
|
const messageString = "Loaded " + this.name;
|
|
if (Manager.getInstance().showNoticeOnGroupLoad === "short") {
|
|
new import_obsidian.Notice(messageString);
|
|
} else if (Manager.getInstance().showNoticeOnGroupLoad === "normal") {
|
|
new import_obsidian.Notice(messageString + "\n" + this.getGroupListString());
|
|
}
|
|
}
|
|
}
|
|
disable() {
|
|
if (!this.groupActive()) {
|
|
return;
|
|
}
|
|
this.plugins.forEach((plugin) => {
|
|
PluginManager.queueDisablePlugin(plugin);
|
|
});
|
|
this.groupIds.forEach((groupId) => {
|
|
var _a;
|
|
(_a = groupFromId(groupId)) == null ? void 0 : _a.disable();
|
|
});
|
|
if (Manager.getInstance().showNoticeOnGroupLoad !== "none") {
|
|
const messageString = "Disabled " + this.name;
|
|
if (Manager.getInstance().showNoticeOnGroupLoad === "short") {
|
|
new import_obsidian.Notice(messageString);
|
|
} else if (Manager.getInstance().showNoticeOnGroupLoad === "normal") {
|
|
new import_obsidian.Notice(messageString + "\n" + this.getGroupListString());
|
|
}
|
|
}
|
|
}
|
|
getGroupListString() {
|
|
const existingPluginsInGroup = PluginManager.getAllAvailablePlugins().filter((p) => this.plugins.map((p2) => p2.id).contains(p.id));
|
|
let messageString = "";
|
|
this.plugins && this.plugins.length > 0 ? messageString += "- Plugins:\n" + existingPluginsInGroup.map((p) => " - " + p.name + "\n").join("") : messageString += "";
|
|
this.groupIds && this.groupIds.length > 0 ? messageString += "- Groups:\n" + this.groupIds.map((g) => {
|
|
const group = groupFromId(g);
|
|
if (group && group.groupActive()) {
|
|
return " - " + group.name + "\n";
|
|
}
|
|
}).join("") : messageString += "";
|
|
return messageString;
|
|
}
|
|
addPlugin(plugin) {
|
|
if (this.plugins.map((p) => p.id).contains(plugin.id))
|
|
return false;
|
|
this.plugins.push(plugin);
|
|
return true;
|
|
}
|
|
addGroup(group) {
|
|
if (!group.wouldHaveCyclicGroups(this.id)) {
|
|
if (this.groupIds.contains(group.id))
|
|
return false;
|
|
this.groupIds.push(group.id);
|
|
return true;
|
|
} else {
|
|
new import_obsidian.Notice("Couldn't add this group, it would create a loop of group activations:\n Group A \u2192 Group B \u2192 Group A", 4e3);
|
|
}
|
|
return false;
|
|
}
|
|
removePlugin(plugin) {
|
|
const indexOfPlugin = this.plugins.map((p) => p.id).indexOf(plugin.id);
|
|
if (indexOfPlugin === -1)
|
|
return true;
|
|
return this.plugins.splice(indexOfPlugin, 1).length > 0;
|
|
}
|
|
removeGroup(group) {
|
|
const indexOfGroup = this.groupIds.indexOf(group.id);
|
|
if (indexOfGroup === -1)
|
|
return true;
|
|
return this.groupIds.splice(indexOfGroup, 1).length > 0;
|
|
}
|
|
wouldHaveCyclicGroups(idToCheck) {
|
|
var _a;
|
|
if (this.id === idToCheck) {
|
|
return true;
|
|
}
|
|
for (let i = 0; i < this.groupIds.length; i++) {
|
|
const groupId = this.groupIds[i];
|
|
if ((_a = groupFromId(groupId)) == null ? void 0 : _a.wouldHaveCyclicGroups(idToCheck)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
getAllPluginIdsControlledByGroup() {
|
|
let pluginsArr = this.plugins.map((plugin) => plugin.id);
|
|
this.groupIds.forEach((gid) => {
|
|
const group = groupFromId(gid);
|
|
if (group) {
|
|
pluginsArr = [
|
|
...pluginsArr,
|
|
...group.getAllPluginIdsControlledByGroup()
|
|
];
|
|
}
|
|
});
|
|
return new Set(pluginsArr);
|
|
}
|
|
};
|
|
|
|
// src/Managers/Manager.ts
|
|
var import_obsidian13 = require("obsidian");
|
|
|
|
// src/Components/BaseComponents/HtmlComponent.ts
|
|
var HtmlComponent = class {
|
|
constructor(parentElement, options) {
|
|
this.parentEl = parentElement;
|
|
if (options) {
|
|
this.options = options;
|
|
}
|
|
}
|
|
update(options) {
|
|
if (options) {
|
|
this.options = options;
|
|
}
|
|
this.render();
|
|
}
|
|
render() {
|
|
if (!this.mainEl) {
|
|
this.generateComponent();
|
|
} else {
|
|
this.clear();
|
|
this.generateContent();
|
|
}
|
|
}
|
|
generateComponent() {
|
|
this.generateContainer();
|
|
this.generateContent();
|
|
}
|
|
clear() {
|
|
if (this.mainEl) {
|
|
this.mainEl.textContent = "";
|
|
}
|
|
}
|
|
};
|
|
|
|
// src/Components/Settings/GroupSettings.ts
|
|
var import_obsidian12 = require("obsidian");
|
|
|
|
// src/Components/Modals/GroupEditModal.ts
|
|
var import_obsidian11 = require("obsidian");
|
|
|
|
// src/Components/BaseComponents/ConfirmationPopupModal.ts
|
|
var import_obsidian2 = require("obsidian");
|
|
var ConfirmationPopupModal = class extends import_obsidian2.Modal {
|
|
constructor(app2, headerText, cancelText, confirmText, onConfirmListener) {
|
|
super(app2);
|
|
this.onConfirm = new Event("onConfirm");
|
|
this.headerText = headerText;
|
|
this.eventTarget = new EventTarget();
|
|
this.cancelText = cancelText != null ? cancelText : "Cancel";
|
|
this.confirmText = confirmText != null ? confirmText : "Confirm";
|
|
this.onConfirmListener = onConfirmListener;
|
|
if (this.onConfirmListener) {
|
|
this.eventTarget.addEventListener(this.onConfirm.type, this.onConfirmListener);
|
|
}
|
|
}
|
|
onOpen() {
|
|
const { contentEl } = this;
|
|
contentEl.empty();
|
|
contentEl.createEl("h2", { text: this.headerText });
|
|
new import_obsidian2.Setting(contentEl).addButton((btn) => {
|
|
btn.setButtonText(this.cancelText);
|
|
btn.onClick(() => this.close());
|
|
}).addButton((btn) => {
|
|
btn.setButtonText(this.confirmText);
|
|
btn.onClick(() => {
|
|
this.eventTarget.dispatchEvent(this.onConfirm);
|
|
if (this.onConfirmListener) {
|
|
this.eventTarget.removeEventListener(this.onConfirm.type, this.onConfirmListener);
|
|
}
|
|
this.close();
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
// src/GroupEditModal/GroupEditPluginsTab.ts
|
|
var import_obsidian7 = require("obsidian");
|
|
|
|
// src/Components/BaseComponents/DropdownActionButton.ts
|
|
var import_obsidian3 = require("obsidian");
|
|
var DropdownActionButton = class extends HtmlComponent {
|
|
constructor(parentElement, options) {
|
|
super(parentElement, options);
|
|
this.generateComponent();
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createEl("button", {
|
|
cls: "pg-drp-btn pg-has-dropdown-single"
|
|
});
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
const { dropDownOptions, mainLabel, drpIcon, minWidth } = this.options;
|
|
if (minWidth) {
|
|
this.mainEl.style.minWidth = minWidth;
|
|
}
|
|
const activeOptionBtn = this.mainEl.createSpan({
|
|
cls: "pg-drp-btn-main-label"
|
|
});
|
|
this.setElementTextOrIcon(activeOptionBtn, mainLabel.label, mainLabel.icon);
|
|
if (drpIcon) {
|
|
const iconSpan = this.mainEl.createSpan();
|
|
(0, import_obsidian3.setIcon)(iconSpan, drpIcon);
|
|
iconSpan.style.paddingTop = "12px";
|
|
} else {
|
|
this.mainEl.createSpan({ text: "\u25BC" });
|
|
}
|
|
this.drpList = this.mainEl.createEl("ul", { cls: "pg-dropdown" });
|
|
dropDownOptions.forEach((option) => {
|
|
const item = this.drpList.createEl("li", {
|
|
cls: "pg-dropdown-item"
|
|
});
|
|
this.setElementTextOrIcon(item, option.label, option.icon);
|
|
item.onClickEvent(() => {
|
|
option.func();
|
|
});
|
|
});
|
|
}
|
|
setElementTextOrIcon(element, label, icon) {
|
|
if (icon) {
|
|
(0, import_obsidian3.setIcon)(element.createSpan(), icon);
|
|
} else {
|
|
element.setText(label);
|
|
}
|
|
}
|
|
};
|
|
|
|
// src/Components/PluginListTogglable.ts
|
|
var import_obsidian4 = require("obsidian");
|
|
var PluginListTogglable = class {
|
|
constructor(parentEL, pluginsToDisplay, actionOption) {
|
|
this.pluginListTarget = new EventTarget();
|
|
this.plugins = pluginsToDisplay;
|
|
this.parentEL = parentEL;
|
|
if (actionOption) {
|
|
this.ownerGroup = actionOption == null ? void 0 : actionOption.group;
|
|
this.pluginListTarget.addEventListener("listToggleClicked", (evt) => {
|
|
actionOption.onClickAction(evt.detail);
|
|
});
|
|
}
|
|
this.generateList();
|
|
}
|
|
updateList(pluginsToDisplay) {
|
|
this.plugins = pluginsToDisplay;
|
|
this.render();
|
|
}
|
|
render() {
|
|
this.pluginListEl.remove();
|
|
this.generateList();
|
|
}
|
|
generateList() {
|
|
this.pluginListEl = this.parentEL.createEl("div");
|
|
this.pluginListEl.addClass("pg-settings-list");
|
|
this.plugins.forEach((plugin) => {
|
|
const setting = new import_obsidian4.Setting(this.pluginListEl).setName(plugin.name);
|
|
if (this.ownerGroup) {
|
|
const btn = new import_obsidian4.ButtonComponent(setting.settingEl);
|
|
this.setIconForPluginBtn(btn, plugin.id);
|
|
btn.onClick(() => {
|
|
this.pluginListTarget.dispatchEvent(new CustomEvent("listToggleClicked", { detail: plugin }));
|
|
this.setIconForPluginBtn(btn, plugin.id);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
setIconForPluginBtn(btn, pluginId2) {
|
|
if (!this.ownerGroup) {
|
|
return;
|
|
}
|
|
btn.setIcon(this.ownerGroup.plugins.map((p) => p.id).contains(pluginId2) ? "check-circle" : "circle");
|
|
}
|
|
};
|
|
|
|
// src/Components/BaseComponents/RemovableChip.ts
|
|
var import_obsidian5 = require("obsidian");
|
|
var RemovableChip = class extends HtmlComponent {
|
|
constructor(parentEl, options) {
|
|
super(parentEl);
|
|
this.parentEl = parentEl;
|
|
this.options = options;
|
|
this.render();
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
this.mainEl.createSpan({ text: this.options.label });
|
|
const closeBtn = this.mainEl.createDiv({ cls: "pg-chip-close-btn" });
|
|
(0, import_obsidian5.setIcon)(closeBtn, "x", 1);
|
|
closeBtn.onClickEvent(() => {
|
|
var _a;
|
|
this.options.onClose();
|
|
(_a = this.mainEl) == null ? void 0 : _a.remove();
|
|
});
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createDiv({ cls: "pg-chip" });
|
|
}
|
|
};
|
|
|
|
// src/Components/FilteredGroupsList.ts
|
|
var FilteredGroupsList = class {
|
|
constructor(parentEl, groups, onChipClosed) {
|
|
this.groups = groups;
|
|
this.parentEl = parentEl;
|
|
this.onChipClosed = onChipClosed;
|
|
this.render();
|
|
}
|
|
update(groups) {
|
|
this.listEL.remove();
|
|
this.groups = groups;
|
|
this.render();
|
|
}
|
|
render() {
|
|
this.listEL = this.parentEl.createDiv({ cls: "pg-group-filter-list" });
|
|
this.listEL.createSpan({ text: "Filters:" });
|
|
this.groups.forEach((group) => {
|
|
new RemovableChip(this.listEL, {
|
|
label: group.name,
|
|
onClose: () => {
|
|
this.groups.delete(group.id);
|
|
this.onChipClosed();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
// src/Components/BaseComponents/SettingsList.ts
|
|
var SettingsList = class extends HtmlComponent {
|
|
constructor(parentEL, options) {
|
|
super(parentEL, options);
|
|
this.generateComponent();
|
|
}
|
|
generateComponent() {
|
|
this.generateContainer();
|
|
this.generateContent();
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createEl("div");
|
|
this.mainEl.addClass("pg-settings-list");
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
const container = this.mainEl;
|
|
this.options.items.forEach((item) => {
|
|
this.generateListItem(container, item);
|
|
});
|
|
}
|
|
clear() {
|
|
if (this.mainEl && this.mainEl.hasClass("pg-settings-list")) {
|
|
this.mainEl.textContent = "";
|
|
}
|
|
}
|
|
};
|
|
|
|
// src/Components/BaseComponents/ReorderableList.ts
|
|
var import_obsidian6 = require("obsidian");
|
|
var ReorderableList = class extends SettingsList {
|
|
moveItemUp(item) {
|
|
const currentIndex = this.findIndexInItems(item);
|
|
if (currentIndex < this.options.items.length - 1 && currentIndex > -1) {
|
|
this.options.items[currentIndex] = this.options.items[currentIndex + 1];
|
|
this.options.items[currentIndex + 1] = item;
|
|
}
|
|
this.render();
|
|
}
|
|
moveItemDown(item) {
|
|
const currentIndex = this.findIndexInItems(item);
|
|
if (currentIndex > 0) {
|
|
this.options.items[currentIndex] = this.options.items[currentIndex - 1];
|
|
this.options.items[currentIndex - 1] = item;
|
|
}
|
|
this.render();
|
|
}
|
|
findIndexInItems(item) {
|
|
return this.options.items.findIndex((listItem) => listItem === item);
|
|
}
|
|
generateListItem(listEl, item) {
|
|
const itemEl = new import_obsidian6.Setting(listEl).addButton((btn) => {
|
|
(0, import_obsidian6.setIcon)(btn.buttonEl, "arrow-down");
|
|
btn.onClick(() => {
|
|
this.moveItemUp(item);
|
|
});
|
|
}).addButton((btn) => {
|
|
(0, import_obsidian6.setIcon)(btn.buttonEl, "arrow-up");
|
|
btn.onClick(() => {
|
|
this.moveItemDown(item);
|
|
});
|
|
});
|
|
return itemEl;
|
|
}
|
|
};
|
|
|
|
// src/Components/ReorderablePluginList.ts
|
|
var ReorderablePluginList = class extends ReorderableList {
|
|
generateListItem(listEl, item) {
|
|
const itemEl = super.generateListItem(listEl, item).setName(item.name);
|
|
return itemEl;
|
|
}
|
|
};
|
|
|
|
// src/Components/BaseComponents/TabGroupComponent.ts
|
|
var TabGroupComponent = class extends HtmlComponent {
|
|
constructor(parentEL, options) {
|
|
super(parentEL, options);
|
|
this.generateComponent();
|
|
}
|
|
switchActiveTab(newActiveTab, newActiveContent) {
|
|
var _a, _b, _c, _d;
|
|
(_a = this.activeTab) == null ? void 0 : _a.removeClass("is-active");
|
|
(_b = this.activeContent) == null ? void 0 : _b.removeClass("is-active");
|
|
this.activeTab = newActiveTab;
|
|
this.activeContent = newActiveContent;
|
|
(_c = this.activeTab) == null ? void 0 : _c.addClass("is-active");
|
|
(_d = this.activeContent) == null ? void 0 : _d.addClass("is-active");
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
const tabContainer = this.mainEl.createDiv({ cls: "pg-tabs" });
|
|
const contentContainer = this.mainEl.createDiv();
|
|
this.options.tabs.forEach((tab, index) => {
|
|
const tabEl = tabContainer == null ? void 0 : tabContainer.createDiv({ cls: "pg-tab" });
|
|
tabEl.createSpan({ text: tab.title });
|
|
const contentEl = contentContainer.appendChild(tab.content);
|
|
contentEl.addClass("pg-tabbed-content");
|
|
tabEl.onClickEvent(() => this.switchActiveTab(tabEl, contentEl));
|
|
if (index === 0) {
|
|
this.switchActiveTab(tabEl, contentEl);
|
|
}
|
|
});
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createDiv();
|
|
}
|
|
};
|
|
|
|
// src/GroupEditModal/GroupEditPluginsTab.ts
|
|
var GroupEditPluginsTab = class extends HtmlComponent {
|
|
constructor(parentElement, options) {
|
|
super(parentElement, options);
|
|
this.availablePlugins = PluginManager.getAllAvailablePlugins();
|
|
this.sortModes = {
|
|
byName: "By Name",
|
|
byNameAndSelected: "By Name & Selected"
|
|
};
|
|
this.selectedSortMode = this.sortModes.byNameAndSelected;
|
|
this.filteredGroups = /* @__PURE__ */ new Map();
|
|
this.filteredPlugins = this.availablePlugins;
|
|
this.generateComponent();
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createDiv();
|
|
this.mainEl.createEl("h5", { text: "Plugins" });
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
const mainPluginSection = this.mainEl.createEl("div");
|
|
const filterSection = this.createFilterSection(mainPluginSection);
|
|
this.pluginsList = new PluginListTogglable(mainPluginSection, this.sortPlugins(this.filteredPlugins, this.selectedSortMode), {
|
|
group: this.options.group,
|
|
onClickAction: (plugin) => this.togglePluginForGroup(plugin)
|
|
});
|
|
const reorderPluginSection = new ReorderablePluginList(this.mainEl.createDiv(), {
|
|
items: this.options.group.plugins
|
|
}).mainEl;
|
|
new TabGroupComponent(this.mainEl, {
|
|
tabs: [
|
|
{
|
|
title: "Main",
|
|
content: mainPluginSection
|
|
},
|
|
{
|
|
title: "Order",
|
|
content: reorderPluginSection != null ? reorderPluginSection : createSpan("No Plugins loaded, please contact Dev")
|
|
}
|
|
]
|
|
});
|
|
}
|
|
createFilterSection(parentEl) {
|
|
const filterSection = parentEl.createDiv();
|
|
new import_obsidian7.Setting(filterSection).setName("Search").addText((txt) => {
|
|
txt.setPlaceholder("Search for Plugin...");
|
|
txt.onChange((search) => {
|
|
this.searchPlugins(search);
|
|
});
|
|
});
|
|
const filtersAndSelectionContainer = filterSection.createDiv({
|
|
cls: "pg-plugin-filter-container"
|
|
});
|
|
const filtersAndSelection = filtersAndSelectionContainer.createDiv({
|
|
cls: "pg-plugin-filter-section"
|
|
});
|
|
const filters = filtersAndSelection.createDiv();
|
|
const filteredGroupsChips = new FilteredGroupsList(filtersAndSelectionContainer, this.filteredGroups, () => this.filterAndSortPlugins());
|
|
const toggleGroupFilter = (group) => {
|
|
this.filteredGroups.has(group.id) ? this.filteredGroups.delete(group.id) : this.filteredGroups.set(group.id, group);
|
|
};
|
|
const updateGroupFilters = () => {
|
|
filteredGroupsChips.update(this.filteredGroups);
|
|
this.filterAndSortPlugins();
|
|
};
|
|
const groupFilterOptions = [
|
|
{
|
|
label: "All groups",
|
|
func: () => {
|
|
if (this.filteredGroups.size === Manager.getInstance().groupsMap.size) {
|
|
this.filteredGroups.clear();
|
|
} else {
|
|
this.filteredGroups = new Map(Manager.getInstance().groupsMap);
|
|
}
|
|
updateGroupFilters();
|
|
}
|
|
}
|
|
];
|
|
Manager.getInstance().groupsMap.forEach((group) => {
|
|
groupFilterOptions.push({
|
|
label: group.name,
|
|
func: () => {
|
|
toggleGroupFilter(group);
|
|
updateGroupFilters();
|
|
}
|
|
});
|
|
});
|
|
new DropdownActionButton(filters, {
|
|
mainLabel: {
|
|
label: "Filter Groups"
|
|
},
|
|
dropDownOptions: groupFilterOptions,
|
|
drpIcon: "filter"
|
|
});
|
|
const sortButton = new DropdownActionButton(filters, {
|
|
mainLabel: {
|
|
label: "Sort"
|
|
},
|
|
dropDownOptions: [
|
|
{
|
|
label: this.sortModes.byName,
|
|
func: () => {
|
|
this.onSortModeChanged(this.sortModes.byName, sortButton);
|
|
}
|
|
},
|
|
{
|
|
label: this.sortModes.byNameAndSelected,
|
|
func: () => {
|
|
this.onSortModeChanged(this.sortModes.byNameAndSelected, sortButton);
|
|
}
|
|
}
|
|
],
|
|
minWidth: "80px",
|
|
drpIcon: "sort-desc"
|
|
});
|
|
new DropdownActionButton(filtersAndSelection, {
|
|
mainLabel: {
|
|
label: "Bulk Select"
|
|
},
|
|
dropDownOptions: [
|
|
{
|
|
label: "Select all",
|
|
func: () => this.selectAllFilteredPlugins()
|
|
},
|
|
{
|
|
label: "Deselect all",
|
|
func: () => this.deselectAllFilteredPlugins()
|
|
}
|
|
]
|
|
});
|
|
return filterSection;
|
|
}
|
|
onSortModeChanged(sortMode, sortButton) {
|
|
this.selectedSortMode = sortMode;
|
|
sortButton.options.mainLabel.label = sortMode;
|
|
sortButton.update();
|
|
this.filterAndSortPlugins();
|
|
}
|
|
filterAndSortPlugins() {
|
|
this.filteredPlugins = this.availablePlugins;
|
|
if (this.searchTerm && this.searchTerm !== "") {
|
|
this.filteredPlugins = this.filteredPlugins.filter((p) => p.name.toLowerCase().contains(this.searchTerm.toLowerCase()));
|
|
}
|
|
if (this.filteredGroups.size > 0) {
|
|
this.filteredPlugins = this.filterPluginsByGroups(this.filteredPlugins, this.filteredGroups);
|
|
}
|
|
this.filteredPlugins = this.sortPlugins(this.filteredPlugins, this.selectedSortMode);
|
|
this.showFilteredPlugins();
|
|
}
|
|
filterPluginsByGroups(pluginsToFilter, groupsToExclude) {
|
|
const pluginMembershipMap = Manager.getInstance().mapOfPluginsDirectlyConnectedGroups;
|
|
return pluginsToFilter.filter((plugin) => {
|
|
var _a;
|
|
if (!pluginMembershipMap.has(plugin.id)) {
|
|
return true;
|
|
}
|
|
for (const groupId of (_a = pluginMembershipMap.get(plugin.id)) != null ? _a : []) {
|
|
if (groupsToExclude.has(groupId)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
searchPlugins(search) {
|
|
this.searchTerm = search;
|
|
this.filterAndSortPlugins();
|
|
this.showFilteredPlugins();
|
|
}
|
|
showFilteredPlugins() {
|
|
this.pluginsList.updateList(this.filteredPlugins);
|
|
}
|
|
deselectAllFilteredPlugins() {
|
|
this.filteredPlugins.forEach((plugin) => this.options.group.removePlugin(plugin));
|
|
this.showFilteredPlugins();
|
|
}
|
|
selectAllFilteredPlugins() {
|
|
this.filteredPlugins.forEach((plugin) => this.options.group.addPlugin(plugin));
|
|
this.showFilteredPlugins();
|
|
}
|
|
sortPlugins(plugins, sortMode) {
|
|
if (!plugins || !(typeof plugins[Symbol.iterator] === "function")) {
|
|
return [];
|
|
}
|
|
const sortedArray = [...plugins];
|
|
if (sortMode === this.sortModes.byName) {
|
|
return sortedArray.sort((a, b) => a.name.localeCompare(b.name));
|
|
}
|
|
if (sortMode === this.sortModes.byNameAndSelected) {
|
|
sortedArray.sort((a, b) => a.name.localeCompare(b.name));
|
|
sortedArray.sort((a, b) => {
|
|
const aInGroup = this.isPluginInGroup(a);
|
|
const bInGroup = this.isPluginInGroup(b);
|
|
if (aInGroup && !bInGroup)
|
|
return -1;
|
|
else if (!aInGroup && bInGroup)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
});
|
|
}
|
|
return sortedArray;
|
|
}
|
|
isPluginInGroup(plugin) {
|
|
return this.options.group.plugins.map((p) => p.id).contains(plugin.id);
|
|
}
|
|
togglePluginForGroup(plugin) {
|
|
const { group } = this.options;
|
|
group.plugins.filter((p) => p.id === plugin.id).length > 0 ? group.removePlugin(plugin) : group.addPlugin(plugin);
|
|
}
|
|
};
|
|
|
|
// src/GroupEditModal/GroupEditGroupsTab.ts
|
|
var import_obsidian8 = require("obsidian");
|
|
var GroupEditGroupsTab = class {
|
|
constructor(group, parentEl) {
|
|
this.groupListElements = /* @__PURE__ */ new Map();
|
|
this.groupToEdit = group;
|
|
this.availableGroups = Array.from(Manager.getInstance().groupsMap.values()).filter((g) => g.id !== group.id);
|
|
this.containerEl = this.generateGroupsSection(parentEl);
|
|
}
|
|
generateGroupsSection(parentElement) {
|
|
const groupSection = parentElement.createDiv();
|
|
groupSection.createEl("h5", { text: "Groups" });
|
|
const searchAndList = groupSection.createEl("div");
|
|
new import_obsidian8.Setting(searchAndList).setName("Search").addText((txt) => {
|
|
txt.setPlaceholder("Search for Groups...");
|
|
txt.onChange((search) => {
|
|
this.searchGroups(search);
|
|
});
|
|
});
|
|
const groupList = searchAndList.createEl("div");
|
|
groupList.addClass("pg-settings-list");
|
|
this.groupListElements = /* @__PURE__ */ new Map();
|
|
this.sortGroups(this.availableGroups).forEach((pluginGroup) => {
|
|
const setting = new import_obsidian8.Setting(groupList).setName(pluginGroup.name).addButton((btn) => {
|
|
btn.setIcon(this.groupToEdit.groupIds.contains(pluginGroup.id) ? "check-circle" : "circle").onClick(() => {
|
|
this.toggleGroupForGroup(pluginGroup);
|
|
btn.setIcon(this.groupToEdit.groupIds.contains(pluginGroup.id) ? "check-circle" : "circle");
|
|
});
|
|
});
|
|
this.groupListElements.set(pluginGroup.id, setting);
|
|
});
|
|
return groupSection;
|
|
}
|
|
searchGroups(search) {
|
|
const hits = this.availableGroups.filter((p) => p.name.toLowerCase().contains(search.toLowerCase())).map((p) => p.id);
|
|
this.groupListElements.forEach((group) => group.settingEl.hide());
|
|
hits.forEach((id) => {
|
|
var _a;
|
|
return (_a = this.groupListElements.get(id)) == null ? void 0 : _a.settingEl.show();
|
|
});
|
|
}
|
|
sortGroups(groups) {
|
|
return groups.sort((a, b) => {
|
|
const aInGroup = this.isGroupInGroup(a);
|
|
const bInGroup = this.isGroupInGroup(b);
|
|
if (aInGroup && !bInGroup)
|
|
return -1;
|
|
else if (!aInGroup && bInGroup)
|
|
return 1;
|
|
else {
|
|
return a.name.localeCompare(b.name);
|
|
}
|
|
});
|
|
}
|
|
isGroupInGroup(plugin) {
|
|
return this.groupToEdit.plugins.map((p) => p.id).contains(plugin.id);
|
|
}
|
|
toggleGroupForGroup(group) {
|
|
if (this.groupToEdit.groupIds.contains(group.id)) {
|
|
return this.groupToEdit.removeGroup(group);
|
|
} else {
|
|
return this.groupToEdit.addGroup(group);
|
|
}
|
|
}
|
|
};
|
|
|
|
// src/GroupEditModal/GroupEditGeneralTab.ts
|
|
var import_obsidian10 = require("obsidian");
|
|
|
|
// src/Components/DeviceSelectionModal.ts
|
|
var import_obsidian9 = require("obsidian");
|
|
var DeviceSelectionModal = class extends import_obsidian9.Modal {
|
|
constructor(app2, onConfirmSelectionListener, selectedDevices) {
|
|
var _a;
|
|
super(app2);
|
|
this.eventTarget = new EventTarget();
|
|
this.onConfirm = new CustomEvent("onConfirm", {
|
|
detail: {
|
|
devices: []
|
|
}
|
|
});
|
|
this.selectedDevices = /* @__PURE__ */ new Set();
|
|
this.headerText = "New device detected please enter a unique name.";
|
|
this.cancelText = "Cancel";
|
|
this.confirmText = "Confirm";
|
|
this.selectedDevices = new Set(selectedDevices);
|
|
if (((_a = this.selectedDevices) == null ? void 0 : _a.size) > 0) {
|
|
this.onConfirm.detail.devices = Array.from(this.selectedDevices.values());
|
|
}
|
|
this.eventTarget.addEventListener(this.onConfirm.type, onConfirmSelectionListener);
|
|
}
|
|
onOpen() {
|
|
const { contentEl } = this;
|
|
contentEl.empty();
|
|
contentEl.createEl("h2", { text: this.headerText });
|
|
contentEl.createEl("h6", { text: "Existing Devices" });
|
|
Manager.getInstance().devices.forEach((device) => {
|
|
new import_obsidian9.Setting(contentEl).setName(device).addButton((tgl) => {
|
|
tgl.setIcon(this.selectedDevices.has(device) ? "check-circle" : "circle").onClick(() => {
|
|
if (this.selectedDevices.has(device)) {
|
|
this.selectedDevices.delete(device);
|
|
tgl.setIcon("circle");
|
|
} else {
|
|
this.selectedDevices.add(device);
|
|
tgl.setIcon("check-circle");
|
|
}
|
|
});
|
|
});
|
|
});
|
|
new import_obsidian9.Setting(contentEl).addButton((btn) => {
|
|
btn.setButtonText(this.cancelText);
|
|
btn.onClick(() => this.close());
|
|
}).addButton((btn) => {
|
|
btn.setButtonText(this.confirmText);
|
|
btn.onClick(() => {
|
|
this.onConfirm.detail.devices = Array.from(this.selectedDevices.values());
|
|
this.eventTarget.dispatchEvent(this.onConfirm);
|
|
this.close();
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
// src/GroupEditModal/GroupEditGeneralTab.ts
|
|
var GroupEditGeneralTab = class {
|
|
constructor(group, parentEl) {
|
|
this.groupToEdit = group;
|
|
this.containerEl = this.generateGeneralSettingsSection(parentEl);
|
|
}
|
|
generateGeneralSettingsSection(contentEl) {
|
|
const generalSettingsSection = contentEl.createDiv();
|
|
generalSettingsSection.createEl("h5", { text: "General" });
|
|
new import_obsidian10.Setting(generalSettingsSection).setName("Commands").setDesc("Add Commands to enable/disable this group").addToggle((tgl) => {
|
|
tgl.setValue(this.groupToEdit.generateCommands);
|
|
tgl.onChange((value) => this.groupToEdit.generateCommands = value);
|
|
});
|
|
new import_obsidian10.Setting(generalSettingsSection).setName("Auto Add").setDesc("Automatically add new Plugins to this group").addToggle((tgl) => {
|
|
var _a;
|
|
tgl.setValue((_a = this.groupToEdit.autoAdd) != null ? _a : false);
|
|
tgl.onChange((value) => this.groupToEdit.autoAdd = value);
|
|
});
|
|
const devicesSetting = new import_obsidian10.Setting(generalSettingsSection).setName("Devices").setDesc(this.getDevicesDescription()).addButton((btn) => {
|
|
btn.setIcon("pencil").onClick(() => {
|
|
new DeviceSelectionModal(app, (evt) => {
|
|
this.groupToEdit.assignedDevices = evt.detail.devices;
|
|
devicesSetting.setDesc(this.getDevicesDescription());
|
|
}, this.groupToEdit.assignedDevices).open();
|
|
});
|
|
});
|
|
this.GenerateStartupSettings(generalSettingsSection);
|
|
return generalSettingsSection;
|
|
}
|
|
getDevicesDescription() {
|
|
let description = "Active on All devices";
|
|
if (!this.groupToEdit.assignedDevices) {
|
|
return description;
|
|
}
|
|
const arr = this.groupToEdit.assignedDevices.filter((device) => Manager.getInstance().devices.contains(device));
|
|
if ((arr == null ? void 0 : arr.length) > 0) {
|
|
description = "Active on: " + arr.reduce((acc, curr, i, arr2) => {
|
|
if (i < 3) {
|
|
return acc + ", " + curr;
|
|
} else if (i === arr2.length - 1) {
|
|
return acc + ", ... and " + (i - 2) + " other" + (i - 2 > 1 ? "s" : "");
|
|
}
|
|
return acc;
|
|
});
|
|
}
|
|
return description;
|
|
}
|
|
GenerateStartupSettings(contentEl) {
|
|
const startupParent = contentEl.createEl("div");
|
|
startupParent.createEl("h6", { text: "Startup" });
|
|
let delaySetting;
|
|
let behaviourElement;
|
|
const ChangeOptionVisibility = () => {
|
|
if (delaySetting) {
|
|
this.groupToEdit.loadAtStartup ? delaySetting.settingEl.show() : delaySetting.settingEl.hide();
|
|
}
|
|
if (behaviourElement) {
|
|
this.groupToEdit.loadAtStartup ? behaviourElement.show() : behaviourElement.hide();
|
|
}
|
|
};
|
|
new import_obsidian10.Setting(startupParent).setName("Load on Startup").addDropdown((drp) => {
|
|
behaviourElement = drp.selectEl;
|
|
drp.addOption("enable", "Enable");
|
|
drp.addOption("disable", "Disable");
|
|
drp.setValue(this.groupToEdit.disableOnStartup ? "disable" : "enable");
|
|
drp.onChange((value) => {
|
|
value === "disable" ? this.groupToEdit.disableOnStartup = true : this.groupToEdit.disableOnStartup = false;
|
|
});
|
|
}).addToggle((tgl) => {
|
|
tgl.onChange((value) => {
|
|
this.groupToEdit.loadAtStartup = value;
|
|
ChangeOptionVisibility();
|
|
});
|
|
tgl.setValue(this.groupToEdit.loadAtStartup);
|
|
});
|
|
delaySetting = new import_obsidian10.Setting(startupParent).setName("Delay").addSlider((slider) => {
|
|
slider.setValue(this.groupToEdit.delay);
|
|
slider.setLimits(0, disableStartupTimeout / 1e3, 1);
|
|
slider.onChange((value) => {
|
|
this.groupToEdit.delay = value;
|
|
delaySetting.setDesc(value.toString());
|
|
});
|
|
}).setDesc(this.groupToEdit.delay.toString());
|
|
ChangeOptionVisibility();
|
|
}
|
|
};
|
|
|
|
// src/Managers/CommandManager.ts
|
|
var CommandManager = class {
|
|
constructor() {
|
|
this.enableGroupCommandPrefix = "plugin-groups-enable-";
|
|
this.disableGroupCommandPrefix = "plugin-groups-disable-";
|
|
this.cnEnablePrefix = "Plugin Groups: Enable ";
|
|
this.cnDisablePrefix = "Plugin Groups: Disable ";
|
|
this.commandMap = /* @__PURE__ */ new Map();
|
|
}
|
|
static getInstance() {
|
|
if (!CommandManager.instance) {
|
|
CommandManager.instance = new CommandManager();
|
|
}
|
|
return CommandManager.instance;
|
|
}
|
|
AddGroupCommands(groupID) {
|
|
const group = groupFromId(groupID);
|
|
if (!group)
|
|
return;
|
|
const enableId = this.enableGroupCommandPrefix + group.id;
|
|
this.commandMap.set(enableId, Manager.getInstance().pluginInstance.addCommand({
|
|
id: enableId,
|
|
name: this.cnEnablePrefix + group.name,
|
|
icon: "power",
|
|
checkCallback: (checking) => {
|
|
if (!this.shouldShowCommand(group))
|
|
return false;
|
|
if (checking)
|
|
return true;
|
|
group.enable();
|
|
}
|
|
}));
|
|
const disableId = this.disableGroupCommandPrefix + group.id;
|
|
this.commandMap.set(disableId, Manager.getInstance().pluginInstance.addCommand({
|
|
id: disableId,
|
|
name: this.cnDisablePrefix + group.name,
|
|
icon: "power-off",
|
|
checkCallback: (checking) => {
|
|
if (!this.shouldShowCommand(group))
|
|
return false;
|
|
if (checking)
|
|
return true;
|
|
group.disable();
|
|
}
|
|
}));
|
|
}
|
|
shouldShowCommand(group) {
|
|
if (!Manager.getInstance().groupsMap.has(group.id))
|
|
return false;
|
|
if (!Manager.getInstance().generateCommands)
|
|
return false;
|
|
if (!group.groupActive()) {
|
|
return false;
|
|
}
|
|
return group.generateCommands;
|
|
}
|
|
updateCommand(groupId) {
|
|
const group = groupFromId(groupId);
|
|
if (!group) {
|
|
return;
|
|
}
|
|
let command = this.commandMap.get(this.enableGroupCommandPrefix + group.id);
|
|
if (command) {
|
|
command.name = this.cnEnablePrefix + group.name;
|
|
}
|
|
command = this.commandMap.get(this.disableGroupCommandPrefix + group.id);
|
|
if (command) {
|
|
command.name = this.cnDisablePrefix + group.name;
|
|
}
|
|
}
|
|
};
|
|
|
|
// src/Components/Modals/GroupEditModal.ts
|
|
var GroupEditModal = class extends import_obsidian11.Modal {
|
|
constructor(app2, settingsTab, group) {
|
|
super(app2);
|
|
this.discardChanges = true;
|
|
this.groupSettings = settingsTab;
|
|
this.groupToEdit = group;
|
|
this.groupToEditCache = JSON.stringify(group);
|
|
}
|
|
onOpen() {
|
|
var _a;
|
|
const { modalEl } = this;
|
|
modalEl.empty();
|
|
const contentEl = modalEl.createDiv();
|
|
const nameSettingNameEl = new import_obsidian11.Setting(contentEl).addText((txt) => {
|
|
txt.setValue(this.groupToEdit.name);
|
|
txt.onChange((val) => {
|
|
this.groupToEdit.name = val;
|
|
nameSettingNameEl.setText('Editing "' + this.groupToEdit.name + '"');
|
|
});
|
|
}).nameEl.createEl("h2", {
|
|
text: 'Editing "' + this.groupToEdit.name + '"'
|
|
});
|
|
const tabGroup = new TabGroupComponent(modalEl, {
|
|
tabs: [
|
|
{
|
|
title: "General",
|
|
content: new GroupEditGeneralTab(this.groupToEdit, contentEl).containerEl
|
|
},
|
|
{
|
|
title: "Plugins",
|
|
content: (_a = new GroupEditPluginsTab(contentEl, {
|
|
group: this.groupToEdit
|
|
}).mainEl) != null ? _a : modalEl.createSpan("Plugins Not Loaded, please contact Dev.")
|
|
},
|
|
{
|
|
title: "Groups",
|
|
content: new GroupEditGroupsTab(this.groupToEdit, contentEl).containerEl
|
|
}
|
|
]
|
|
});
|
|
this.generateFooter(modalEl);
|
|
}
|
|
generateFooter(parentElement) {
|
|
const footer = parentElement.createEl("div");
|
|
footer.addClass("pg-edit-modal-footer");
|
|
new import_obsidian11.Setting(footer).addButton((btn) => {
|
|
btn.setButtonText("Delete");
|
|
btn.onClick(() => new ConfirmationPopupModal(this.app, "You are about to delete: " + this.groupToEdit.name, void 0, "Delete", () => this.deleteGroup()).open());
|
|
}).addButton((btn) => {
|
|
btn.setButtonText("Cancel");
|
|
btn.onClick(() => this.close());
|
|
}).addButton((btn) => {
|
|
btn.setButtonText("Save");
|
|
btn.onClick(() => this.saveChanges());
|
|
}).addExtraButton((btn) => {
|
|
btn.setIcon("copy").setTooltip("Duplicate this group").onClick(() => this.duplicate());
|
|
}).settingEl.addClass("modal-footer");
|
|
}
|
|
onClose() {
|
|
const { contentEl } = this;
|
|
contentEl.empty();
|
|
if (Manager.getInstance().groupsMap.has(this.groupToEdit.id) && this.discardChanges) {
|
|
Object.assign(this.groupToEdit, JSON.parse(this.groupToEditCache));
|
|
}
|
|
}
|
|
async saveChanges() {
|
|
this.discardChanges = false;
|
|
if (Manager.getInstance().groupsMap.has(this.groupToEdit.id)) {
|
|
await this.editGroup(this.groupToEdit);
|
|
} else {
|
|
await this.addGroup(this.groupToEdit);
|
|
}
|
|
}
|
|
async duplicate() {
|
|
const duplicateGroup = new PluginGroup(this.groupToEdit);
|
|
const groupMap = Manager.getInstance().groupsMap;
|
|
if (!groupMap) {
|
|
return;
|
|
}
|
|
duplicateGroup.name += "-Duplicate";
|
|
const genId = generateGroupID(duplicateGroup.name);
|
|
if (!genId) {
|
|
return;
|
|
}
|
|
duplicateGroup.id = genId;
|
|
await this.addGroup(duplicateGroup);
|
|
}
|
|
async addGroup(group) {
|
|
Manager.getInstance().groupsMap.set(group.id, group);
|
|
CommandManager.getInstance().AddGroupCommands(group.id);
|
|
await this.persistChangesAndClose();
|
|
}
|
|
async editGroup(group) {
|
|
Manager.getInstance().groupsMap.set(group.id, group);
|
|
CommandManager.getInstance().updateCommand(group.id);
|
|
await this.persistChangesAndClose();
|
|
}
|
|
async persistChangesAndClose() {
|
|
await Manager.getInstance().saveSettings();
|
|
this.groupSettings.render();
|
|
this.close();
|
|
}
|
|
async deleteGroup() {
|
|
Manager.getInstance().groupsMap.delete(this.groupToEdit.id);
|
|
await Manager.getInstance().saveSettings();
|
|
this.groupSettings.render();
|
|
this.close();
|
|
}
|
|
};
|
|
|
|
// src/Components/Settings/GroupSettings.ts
|
|
var GroupSettings = class extends HtmlComponent {
|
|
constructor(parentEL, options) {
|
|
super(parentEL, options);
|
|
this.generateComponent();
|
|
}
|
|
generateContent() {
|
|
var _a, _b;
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
const header = this.mainEl.createEl("h5", { text: "Groups" });
|
|
const content = this.mainEl.createDiv();
|
|
if (this.options.collapsible) {
|
|
makeCollapsible(header, content, this.options.startOpened);
|
|
}
|
|
let addBtnEl;
|
|
new import_obsidian12.Setting(content).setName("Add Group").addText((text) => {
|
|
this.groupNameField = text;
|
|
this.groupNameField.setPlaceholder("Enter group name...").setValue(this.newGroupName).onChange((val) => {
|
|
this.newGroupName = val;
|
|
if (addBtnEl) {
|
|
val.replace(" ", "").length > 0 ? addBtnEl.removeClass("btn-disabled") : addBtnEl.addClass("btn-disabled");
|
|
}
|
|
}).inputEl.onkeydown = async (e) => {
|
|
if (e.key === "Enter") {
|
|
await this.addNewGroup();
|
|
}
|
|
};
|
|
}).addButton((btn) => {
|
|
btn.setIcon("plus").onClick(() => this.addNewGroup());
|
|
addBtnEl = btn.buttonEl;
|
|
addBtnEl.addClass("btn-disabled");
|
|
});
|
|
const listContainer = content.createDiv();
|
|
listContainer.style.overflow = "scroll";
|
|
listContainer.style.maxHeight = ((_b = (_a = this.options.maxListHeight) == null ? void 0 : _a.toString()) != null ? _b : "") + "px";
|
|
this.GenerateGroupList(listContainer);
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createDiv();
|
|
}
|
|
GenerateGroupList(groupParent) {
|
|
Manager.getInstance().groupsMap.forEach((group) => {
|
|
const groupSetting = new import_obsidian12.Setting(groupParent).setName(group.name).addButton((btn) => {
|
|
btn.setButtonText("Enable");
|
|
btn.setIcon("power");
|
|
btn.onClick(async () => {
|
|
await group.enable();
|
|
});
|
|
group.groupActive() ? btn.buttonEl.removeClass("btn-disabled") : btn.buttonEl.addClass("btn-disabled");
|
|
}).addButton((btn) => {
|
|
btn.setButtonText("Disable");
|
|
btn.setIcon("power-off");
|
|
btn.onClick(() => group.disable());
|
|
group.groupActive() ? btn.buttonEl.removeClass("btn-disabled") : btn.buttonEl.addClass("btn-disabled");
|
|
}).addButton((btn) => {
|
|
btn.setIcon("pencil");
|
|
btn.onClick(() => this.editGroup(group));
|
|
});
|
|
if (group.loadAtStartup) {
|
|
const descFrag = new DocumentFragment();
|
|
const startupEl = descFrag.createEl("span");
|
|
startupEl.createEl("b", {
|
|
text: "Startup: "
|
|
});
|
|
startupEl.createEl("span", {
|
|
text: "Delayed by " + group.delay + " seconds"
|
|
});
|
|
if (!group.groupActive()) {
|
|
const activeEl = descFrag.createEl("span");
|
|
activeEl.createEl("br");
|
|
activeEl.createEl("b", { text: "Inactive: " });
|
|
activeEl.createEl("span", {
|
|
text: "Not enabled for current Device"
|
|
});
|
|
}
|
|
groupSetting.setDesc(descFrag);
|
|
}
|
|
});
|
|
}
|
|
async addNewGroup() {
|
|
const id = generateGroupID(this.newGroupName);
|
|
if (!id) {
|
|
console.error("Failed to create Group, please choose a different Name as there have been to many groups with the same name");
|
|
return;
|
|
}
|
|
const newGroup = new PluginGroup({
|
|
id,
|
|
name: this.newGroupName
|
|
});
|
|
new GroupEditModal(Manager.getInstance().pluginInstance.app, this, newGroup).open();
|
|
this.newGroupName = "";
|
|
if (this.groupNameField) {
|
|
this.groupNameField.setValue("");
|
|
}
|
|
}
|
|
editGroup(group) {
|
|
new GroupEditModal(Manager.getInstance().pluginInstance.app, this, group).open();
|
|
}
|
|
};
|
|
|
|
// src/Components/Modals/GroupSettingsMenu.ts
|
|
var GroupSettingsMenu = class extends HtmlComponent {
|
|
constructor(parentEl, options) {
|
|
super(parentEl, options);
|
|
this.generateComponent();
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createDiv({ cls: "pg-settings-window" });
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
new GroupSettings(this.mainEl, { maxListHeight: 340 });
|
|
this.updatePosition();
|
|
}
|
|
updatePosition() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
this.mainEl.style.transform = "translate(0px, 0px)";
|
|
let xOffset = -this.mainEl.getBoundingClientRect().width / 2;
|
|
const yOffset = -this.mainEl.clientHeight / 2 - 30;
|
|
const diff = window.innerWidth - this.mainEl.getBoundingClientRect().right - 16;
|
|
if (diff < 0) {
|
|
xOffset = diff;
|
|
}
|
|
this.mainEl.style.transform = "translate(" + xOffset + "px, " + yOffset + "px)";
|
|
}
|
|
};
|
|
|
|
// src/Managers/Manager.ts
|
|
var DEFAULT_SETTINGS = {
|
|
groupsMap: /* @__PURE__ */ new Map(),
|
|
generateCommands: true,
|
|
showNoticeOnGroupLoad: "none",
|
|
devLogs: false,
|
|
devices: [],
|
|
doLoadSynchronously: true,
|
|
showStatusbarIcon: "None"
|
|
};
|
|
var Manager = class {
|
|
constructor() {
|
|
}
|
|
static getInstance() {
|
|
if (!Manager.instance) {
|
|
Manager.instance = new Manager();
|
|
}
|
|
return Manager.instance;
|
|
}
|
|
async init(main) {
|
|
this.main = main;
|
|
await this.loadSettings();
|
|
return this;
|
|
}
|
|
async loadSettings() {
|
|
const savedSettings = await this.main.loadData();
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS);
|
|
if (!savedSettings) {
|
|
return;
|
|
}
|
|
Object.keys(this.settings).forEach(function(key) {
|
|
if (key in savedSettings) {
|
|
Manager.getInstance().settings[key] = savedSettings[key];
|
|
}
|
|
});
|
|
if (savedSettings.groups && Array.isArray(savedSettings.groups)) {
|
|
this.settings.groupsMap = /* @__PURE__ */ new Map();
|
|
savedSettings.groups.forEach((g) => {
|
|
this.groupsMap.set(g.id, new PluginGroup(g));
|
|
});
|
|
}
|
|
}
|
|
get mapOfPluginsConnectedGroupsIncludingParentGroups() {
|
|
const pluginsMemMap = /* @__PURE__ */ new Map();
|
|
this.groupsMap.forEach((group) => {
|
|
group.getAllPluginIdsControlledByGroup().forEach((plugin) => {
|
|
var _a;
|
|
if (!pluginsMemMap.has(pluginId)) {
|
|
pluginsMemMap.set(plugin, /* @__PURE__ */ new Set());
|
|
}
|
|
(_a = pluginsMemMap.get(plugin)) == null ? void 0 : _a.add(group.id);
|
|
});
|
|
});
|
|
return pluginsMemMap;
|
|
}
|
|
get mapOfPluginsDirectlyConnectedGroups() {
|
|
const pluginsMemMap = /* @__PURE__ */ new Map();
|
|
this.groupsMap.forEach((group) => {
|
|
group.plugins.forEach((plugin) => {
|
|
var _a;
|
|
if (!pluginsMemMap.has(plugin.id)) {
|
|
pluginsMemMap.set(plugin.id, /* @__PURE__ */ new Set());
|
|
}
|
|
(_a = pluginsMemMap.get(plugin.id)) == null ? void 0 : _a.add(group.id);
|
|
});
|
|
});
|
|
return pluginsMemMap;
|
|
}
|
|
getGroupsOfPlugin(pluginId2) {
|
|
const groups = [];
|
|
for (const group of this.groupsMap.values()) {
|
|
if (group.plugins.find((plugin) => plugin.id === pluginId2)) {
|
|
groups.push(group);
|
|
}
|
|
}
|
|
return groups;
|
|
}
|
|
async saveSettings() {
|
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
const persistentSettings = {
|
|
groups: Array.from((_a = this.groupsMap.values()) != null ? _a : []),
|
|
generateCommands: (_b = this.settings.generateCommands) != null ? _b : DEFAULT_SETTINGS.generateCommands,
|
|
showNoticeOnGroupLoad: (_c = this.settings.showNoticeOnGroupLoad) != null ? _c : DEFAULT_SETTINGS.showNoticeOnGroupLoad,
|
|
devLogs: (_d = this.settings.devLogs) != null ? _d : DEFAULT_SETTINGS.devLogs,
|
|
devices: (_e = this.settings.devices) != null ? _e : DEFAULT_SETTINGS.devices,
|
|
doLoadSynchronously: (_f = this.settings.doLoadSynchronously) != null ? _f : DEFAULT_SETTINGS.doLoadSynchronously,
|
|
showStatusbarIcon: (_g = this.settings.showStatusbarIcon) != null ? _g : DEFAULT_SETTINGS.showStatusbarIcon
|
|
};
|
|
await this.main.saveData(persistentSettings);
|
|
}
|
|
get doLoadSynchronously() {
|
|
return this.settings.doLoadSynchronously;
|
|
}
|
|
set doLoadSynchronously(value) {
|
|
this.settings.doLoadSynchronously = value;
|
|
}
|
|
get showStatusbarIcon() {
|
|
return this.settings.showStatusbarIcon;
|
|
}
|
|
set showStatusbarIcon(value) {
|
|
this.settings.showStatusbarIcon = value;
|
|
}
|
|
get devLog() {
|
|
return this.settings.devLogs;
|
|
}
|
|
set devLog(value) {
|
|
this.settings.devLogs = value;
|
|
}
|
|
get pluginInstance() {
|
|
return this.main;
|
|
}
|
|
get pluginsManifests() {
|
|
return this.obsidianPluginsObject.manifests;
|
|
}
|
|
get obsidianPluginsObject() {
|
|
return this.main.app.plugins;
|
|
}
|
|
get groupsMap() {
|
|
return this.settings.groupsMap;
|
|
}
|
|
get generateCommands() {
|
|
return this.settings.generateCommands;
|
|
}
|
|
set shouldGenerateCommands(val) {
|
|
this.settings.generateCommands = val;
|
|
}
|
|
get showNoticeOnGroupLoad() {
|
|
return this.settings.showNoticeOnGroupLoad;
|
|
}
|
|
set showNoticeOnGroupLoad(val) {
|
|
this.settings.showNoticeOnGroupLoad = val;
|
|
}
|
|
get devices() {
|
|
return this.settings.devices;
|
|
}
|
|
updateStatusbarItem() {
|
|
if (this.statusbarItem) {
|
|
this.statusbarItem.remove();
|
|
}
|
|
if (this.showStatusbarIcon === "None") {
|
|
return;
|
|
}
|
|
this.statusbarItem = this.pluginInstance.addStatusBarItem();
|
|
this.statusbarItem.addClasses(["pg-statusbar-icon", "mod-clickable"]);
|
|
this.statusbarItem.tabIndex = 0;
|
|
if (this.showStatusbarIcon === "Text") {
|
|
this.statusbarItem.textContent = "Plugins";
|
|
} else if (this.showStatusbarIcon === "Icon") {
|
|
(0, import_obsidian13.setIcon)(this.statusbarItem, "boxes");
|
|
}
|
|
const menu = new GroupSettingsMenu(this.statusbarItem, {});
|
|
this.statusbarItem.onfocus = () => {
|
|
menu.updatePosition();
|
|
};
|
|
}
|
|
};
|
|
|
|
// src/Utils/Utilities.ts
|
|
var import_obsidian14 = require("obsidian");
|
|
function generateGroupID(name, delay) {
|
|
let id = nameToId((delay ? "stg-" : "pg-") + name);
|
|
const groupMap = Manager.getInstance().groupsMap;
|
|
if (!groupMap) {
|
|
return void 0;
|
|
}
|
|
if (!groupMap.has(id)) {
|
|
return id;
|
|
}
|
|
for (let i = 0; i < 512; i++) {
|
|
const nrdId = id + i.toString();
|
|
id += i.toString();
|
|
if (!groupMap.has(id)) {
|
|
return delay ? nrdId + delay.toString() : nrdId;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
function nameToId(name) {
|
|
return name.replace(/[\W_]/g, "").toLowerCase();
|
|
}
|
|
function saveVaultLocalStorage(key, object) {
|
|
Manager.getInstance().pluginInstance.app.saveLocalStorage(key, object);
|
|
}
|
|
function loadVaultLocalStorage(key) {
|
|
return Manager.getInstance().pluginInstance.app.loadLocalStorage(key);
|
|
}
|
|
function getCurrentlyActiveDevice() {
|
|
const device = loadVaultLocalStorage(deviceNameKey);
|
|
if (typeof device === "string") {
|
|
return device;
|
|
}
|
|
return null;
|
|
}
|
|
function setCurrentlyActiveDevice(device) {
|
|
saveVaultLocalStorage(deviceNameKey, device);
|
|
}
|
|
function groupFromId(id) {
|
|
return Manager.getInstance().groupsMap.get(id);
|
|
}
|
|
function makeCollapsible(foldClickElement, content, startOpened) {
|
|
if (!content.hasClass("pg-collapsible-content")) {
|
|
content.addClass("pg-collapsible-content");
|
|
}
|
|
if (!foldClickElement.hasClass("pg-collapsible-header")) {
|
|
foldClickElement.addClass("pg-collapsible-header");
|
|
}
|
|
toggleCollapsibleIcon(foldClickElement);
|
|
if (startOpened) {
|
|
content.addClass("is-active");
|
|
toggleCollapsibleIcon(foldClickElement);
|
|
}
|
|
foldClickElement.onclick = () => {
|
|
content.hasClass("is-active") ? content.removeClass("is-active") : content.addClass("is-active");
|
|
toggleCollapsibleIcon(foldClickElement);
|
|
};
|
|
}
|
|
function toggleCollapsibleIcon(parentEl) {
|
|
let foldable = parentEl.querySelector(":scope > .pg-collapsible-icon");
|
|
if (!foldable) {
|
|
foldable = parentEl.createSpan({ cls: "pg-collapsible-icon" });
|
|
}
|
|
if (foldable.dataset.togglestate === "up") {
|
|
(0, import_obsidian14.setIcon)(foldable, "chevron-down");
|
|
foldable.dataset.togglestate = "down";
|
|
} else {
|
|
(0, import_obsidian14.setIcon)(foldable, "chevron-up");
|
|
foldable.dataset.togglestate = "up";
|
|
}
|
|
}
|
|
|
|
// src/Components/Settings/AdvancedSettings.ts
|
|
var import_obsidian15 = require("obsidian");
|
|
var AdvancedSettings = class extends HtmlComponent {
|
|
constructor(parentEL, options) {
|
|
super(parentEL, options);
|
|
this.generateComponent();
|
|
}
|
|
generateContent() {
|
|
if (!this.mainEl) {
|
|
return;
|
|
}
|
|
const header = this.mainEl.createEl("h5", {
|
|
text: "Advanced Settings"
|
|
});
|
|
const content = this.mainEl.createDiv();
|
|
if (this.options.collapsible) {
|
|
makeCollapsible(header, content);
|
|
}
|
|
new import_obsidian15.Setting(content).setName("Development Logs").addToggle((tgl) => {
|
|
tgl.setValue(Manager.getInstance().devLog);
|
|
tgl.onChange(async (value) => {
|
|
Manager.getInstance().devLog = value;
|
|
await Manager.getInstance().saveSettings();
|
|
});
|
|
});
|
|
new import_obsidian15.Setting(content).setName("Load Synchronously").addToggle((tgl) => {
|
|
tgl.setValue(Manager.getInstance().doLoadSynchronously);
|
|
tgl.onChange(async (value) => {
|
|
Manager.getInstance().doLoadSynchronously = value;
|
|
await Manager.getInstance().saveSettings();
|
|
});
|
|
});
|
|
}
|
|
generateContainer() {
|
|
this.mainEl = this.parentEl.createDiv();
|
|
}
|
|
};
|
|
|
|
// src/Components/DescriptionsList.ts
|
|
var import_obsidian16 = require("obsidian");
|
|
var DescriptionsList = class extends SettingsList {
|
|
constructor(parentEL, options) {
|
|
super(parentEL, options);
|
|
}
|
|
generateListItem(listEl, plugin) {
|
|
const item = new import_obsidian16.Setting(listEl).setName(plugin.item.name);
|
|
if (plugin.description) {
|
|
item.setDesc(plugin.description);
|
|
}
|
|
return item;
|
|
}
|
|
};
|
|
|
|
// src/Components/Modals/PluginModal.ts
|
|
var import_obsidian18 = require("obsidian");
|
|
|
|
// src/Components/BaseComponents/TogglableList.ts
|
|
var import_obsidian17 = require("obsidian");
|
|
var TogglableList = class extends SettingsList {
|
|
generateListItem(listEl, item) {
|
|
const settingItem = new import_obsidian17.Setting(listEl);
|
|
settingItem.setName(item.name);
|
|
this.addToggleButton(settingItem, item);
|
|
return settingItem;
|
|
}
|
|
addToggleButton(setting, item) {
|
|
setting.addButton((btn) => {
|
|
const currentState = this.getItemState(item);
|
|
this.setToggleIcon(btn, currentState);
|
|
btn.onClick(() => {
|
|
this.toggleItem(item);
|
|
this.setToggleIcon(btn, this.getItemState(item));
|
|
});
|
|
});
|
|
}
|
|
toggleItem(item) {
|
|
this.options.toggle(item);
|
|
}
|
|
getItemState(item) {
|
|
return this.options.getToggleState(item);
|
|
}
|
|
setToggleIcon(btn, value) {
|
|
btn.setIcon(value ? "check-circle" : "circle");
|
|
}
|
|
};
|
|
|
|
// src/Components/Modals/PluginModal.ts
|
|
var PluginModal = class extends import_obsidian18.Modal {
|
|
constructor(app2, pluginToEdit, onCloseActions) {
|
|
super(app2);
|
|
this.discardChanges = true;
|
|
this.pluginToEdit = pluginToEdit;
|
|
this.onCloseActions = onCloseActions;
|
|
this.memberGroupIds = Manager.getInstance().getGroupsOfPlugin(pluginToEdit.id).map((g) => g.id);
|
|
this.memberGroupsIdsCache = this.memberGroupIds.map((id) => id);
|
|
}
|
|
onOpen() {
|
|
const { modalEl } = this;
|
|
modalEl.empty();
|
|
const contentEl = modalEl.createDiv();
|
|
const title = contentEl.createEl("h4");
|
|
title.textContent = "Editing Plugin: ";
|
|
title.createEl("b").textContent = this.pluginToEdit.name;
|
|
if (this.memberGroupIds) {
|
|
const groupsList = new TogglableList(contentEl, {
|
|
items: Array.from(Manager.getInstance().groupsMap.values()),
|
|
getToggleState: (item) => {
|
|
return this.getToggleState(item);
|
|
},
|
|
toggle: (item) => {
|
|
this.toggleItem(item);
|
|
}
|
|
});
|
|
}
|
|
this.generateFooter(contentEl);
|
|
}
|
|
toggleItem(item) {
|
|
if (!this.memberGroupIds.contains(item.id)) {
|
|
this.memberGroupIds.push(item.id);
|
|
} else {
|
|
this.memberGroupIds.remove(item.id);
|
|
}
|
|
}
|
|
getToggleState(item) {
|
|
return this.memberGroupIds && this.memberGroupIds.contains(item.id);
|
|
}
|
|
onClose() {
|
|
const { contentEl } = this;
|
|
if (this.onCloseActions) {
|
|
this.onCloseActions();
|
|
}
|
|
contentEl.empty();
|
|
}
|
|
generateFooter(parentElement) {
|
|
const footer = parentElement.createEl("div");
|
|
footer.addClass("pg-edit-modal-footer");
|
|
new import_obsidian18.Setting(footer).addButton((btn) => {
|
|
btn.setButtonText("Cancel");
|
|
btn.onClick(() => this.close());
|
|
}).addButton((btn) => {
|
|
btn.setButtonText("Save");
|
|
btn.onClick(() => this.saveChanges());
|
|
}).settingEl.addClass("modal-footer");
|
|
}
|
|
async saveChanges() {
|
|
const removedGroupIds = this.memberGroupsIdsCache.filter((id) => !this.memberGroupIds.includes(id));
|
|
removedGroupIds.forEach((id) => {
|
|
var _a;
|
|
return (_a = Manager.getInstance().groupsMap.get(id)) == null ? void 0 : _a.removePlugin(this.pluginToEdit);
|
|
});
|
|
const addedGroupIds = this.memberGroupIds.filter((id) => !this.memberGroupsIdsCache.includes(id));
|
|
addedGroupIds.forEach((id) => {
|
|
var _a;
|
|
(_a = Manager.getInstance().groupsMap.get(id)) == null ? void 0 : _a.addPlugin(this.pluginToEdit);
|
|
});
|
|
await Manager.getInstance().saveSettings();
|
|
this.close();
|
|
}
|
|
};
|
|
|
|
// src/Components/EditPluginList.ts
|
|
var EditPluginList = class extends DescriptionsList {
|
|
constructor(parentEL, options, onEditFinished) {
|
|
super(parentEL, options);
|
|
this.onEditFinished = onEditFinished;
|
|
}
|
|
generateListItem(listEl, plugin) {
|
|
const item = super.generateListItem(listEl, plugin);
|
|
item.addButton((btn) => {
|
|
btn.setIcon("pencil");
|
|
btn.onClick(() => {
|
|
new PluginModal(Manager.getInstance().pluginInstance.app, plugin.item, () => {
|
|
if (this.onEditFinished) {
|
|
this.onEditFinished();
|
|
}
|
|
}).open();
|
|
});
|
|
});
|
|
return item;
|
|
}
|
|
};
|
|
|
|
// src/PluginGroupSettings.ts
|
|
var PluginGroupSettings = class extends import_obsidian19.PluginSettingTab {
|
|
constructor(app2, plugin) {
|
|
super(app2, plugin);
|
|
}
|
|
async display() {
|
|
await PluginManager.loadNewPlugins();
|
|
const { containerEl } = this;
|
|
containerEl.empty();
|
|
this.generateGeneralSettings(containerEl);
|
|
new GroupSettings(containerEl, {
|
|
collapsible: true,
|
|
startOpened: true
|
|
});
|
|
this.GenerateDeviceList(containerEl);
|
|
this.GeneratePluginsList(containerEl);
|
|
new AdvancedSettings(containerEl, { collapsible: true });
|
|
}
|
|
generateGeneralSettings(containerEl) {
|
|
const generalParent = containerEl.createDiv();
|
|
const header = generalParent.createEl("h4", {
|
|
text: "General",
|
|
cls: "mod-clickable"
|
|
});
|
|
const content = generalParent.createDiv();
|
|
makeCollapsible(header, content, true);
|
|
new import_obsidian19.Setting(content).setName("Generate Commands for Groups").addToggle((tgl) => {
|
|
var _a;
|
|
tgl.setValue((_a = Manager.getInstance().generateCommands) != null ? _a : false);
|
|
tgl.onChange(async (value) => {
|
|
Manager.getInstance().shouldGenerateCommands = value;
|
|
await Manager.getInstance().saveSettings();
|
|
});
|
|
});
|
|
new import_obsidian19.Setting(content).setName("Notice upon un-/loading groups").addDropdown((drp) => {
|
|
var _a;
|
|
drp.addOption("none", "None").addOption("short", "Short").addOption("normal", "Normal");
|
|
drp.setValue((_a = Manager.getInstance().showNoticeOnGroupLoad) != null ? _a : "none");
|
|
drp.onChange(async (value) => {
|
|
Manager.getInstance().showNoticeOnGroupLoad = value;
|
|
await Manager.getInstance().saveSettings();
|
|
});
|
|
});
|
|
new import_obsidian19.Setting(content).setName("Statusbar Menu").addDropdown((drp) => {
|
|
var _a;
|
|
drp.addOption("None", "None").addOption("Icon", "Icon").addOption("Text", "Text");
|
|
drp.setValue((_a = Manager.getInstance().showStatusbarIcon) != null ? _a : "None");
|
|
drp.onChange(async (value) => {
|
|
switch (value) {
|
|
case "Icon":
|
|
Manager.getInstance().showStatusbarIcon = "Icon";
|
|
break;
|
|
case "Text":
|
|
Manager.getInstance().showStatusbarIcon = "Text";
|
|
break;
|
|
default:
|
|
Manager.getInstance().showStatusbarIcon = "None";
|
|
break;
|
|
}
|
|
await Manager.getInstance().saveSettings();
|
|
Manager.getInstance().updateStatusbarItem();
|
|
});
|
|
});
|
|
}
|
|
GenerateDeviceList(contentEl) {
|
|
let newDeviceName = "";
|
|
const CreateNewDevice = async () => {
|
|
if (!newDeviceName || newDeviceName.replace(" ", "") === "") {
|
|
return;
|
|
}
|
|
if (Manager.getInstance().devices.contains(newDeviceName)) {
|
|
new import_obsidian19.Notice("Name already in use for other device");
|
|
return;
|
|
}
|
|
Manager.getInstance().devices.push(newDeviceName);
|
|
await Manager.getInstance().saveSettings();
|
|
if (!getCurrentlyActiveDevice()) {
|
|
setCurrentlyActiveDevice(newDeviceName);
|
|
}
|
|
this.display();
|
|
newDeviceName = "";
|
|
newDevNameText.setValue(newDeviceName);
|
|
};
|
|
const header = contentEl.createEl("h4", { text: "Devices" });
|
|
const content = contentEl.createDiv();
|
|
makeCollapsible(header, content);
|
|
let deviceAddBtn;
|
|
const deviceNameSetting = new import_obsidian19.Setting(content).setName("New Device");
|
|
const newDevNameText = new import_obsidian19.TextComponent(deviceNameSetting.controlEl);
|
|
newDevNameText.setValue(newDeviceName).onChange((value) => {
|
|
newDeviceName = value;
|
|
if (deviceAddBtn) {
|
|
value.replace(" ", "").length > 0 ? deviceAddBtn.buttonEl.removeClass("btn-disabled") : deviceAddBtn.buttonEl.addClass("btn-disabled");
|
|
}
|
|
}).setPlaceholder("Device Name").inputEl.onkeydown = async (e) => {
|
|
if (e.key === "Enter") {
|
|
await CreateNewDevice();
|
|
}
|
|
};
|
|
deviceNameSetting.addButton((btn) => {
|
|
deviceAddBtn = btn;
|
|
deviceAddBtn.setIcon("plus").onClick(async () => {
|
|
await CreateNewDevice();
|
|
}).buttonEl.addClass("btn-disabled");
|
|
});
|
|
Manager.getInstance().devices.forEach((device) => {
|
|
const deviceSetting = new import_obsidian19.Setting(content).setName(device);
|
|
if (getCurrentlyActiveDevice() === device) {
|
|
deviceSetting.setDesc("Current Device").addButton((btn) => {
|
|
btn.setIcon("trash");
|
|
btn.onClick(() => new ConfirmationPopupModal(this.app, "This is the currently active device, are you sure?", void 0, "Delete", () => {
|
|
this.ResetCurrentDevice();
|
|
}).open());
|
|
});
|
|
} else {
|
|
deviceSetting.addButton((btn) => {
|
|
btn.setButtonText("Set as Current");
|
|
btn.onClick(() => {
|
|
setCurrentlyActiveDevice(device);
|
|
this.display();
|
|
});
|
|
}).addButton((btn) => {
|
|
btn.setIcon("trash");
|
|
btn.onClick(() => new ConfirmationPopupModal(this.app, "You are about to delete: " + device, void 0, "Delete", async () => {
|
|
Manager.getInstance().devices.remove(device);
|
|
await Manager.getInstance().saveSettings();
|
|
this.display();
|
|
}).open());
|
|
});
|
|
}
|
|
});
|
|
}
|
|
ResetCurrentDevice() {
|
|
const device = getCurrentlyActiveDevice();
|
|
if (!device) {
|
|
return;
|
|
}
|
|
Manager.getInstance().devices.remove(device);
|
|
setCurrentlyActiveDevice(null);
|
|
this.display();
|
|
}
|
|
GeneratePluginsList(parentEl) {
|
|
const header = parentEl.createEl("h4", { text: "Plugins" });
|
|
const content = parentEl.createDiv();
|
|
makeCollapsible(header, content);
|
|
const refresh = new import_obsidian19.ExtraButtonComponent(content);
|
|
refresh.setIcon("refresh-cw");
|
|
refresh.setTooltip("Refresh list for changes to the plugins and assigned groups.");
|
|
const pluginList = new EditPluginList(content, {
|
|
items: this.getPluginsWithGroupsAsDescription()
|
|
}, () => {
|
|
pluginList.update({
|
|
items: this.getPluginsWithGroupsAsDescription()
|
|
});
|
|
});
|
|
refresh.onClick(() => {
|
|
pluginList.update({
|
|
items: this.getPluginsWithGroupsAsDescription()
|
|
});
|
|
});
|
|
}
|
|
getPluginsWithGroupsAsDescription() {
|
|
return PluginManager.getAllAvailablePlugins().map((plugin) => {
|
|
const groups = Manager.getInstance().getGroupsOfPlugin(plugin.id);
|
|
return {
|
|
item: plugin,
|
|
description: groups.map((group) => group.name).join(", ")
|
|
};
|
|
});
|
|
}
|
|
};
|
|
|
|
// main.ts
|
|
var PgMain = class extends import_obsidian20.Plugin {
|
|
async onload() {
|
|
const times = [];
|
|
times.push({ label: "Time on Load", time: this.getCurrentTime() });
|
|
await Manager.getInstance().init(this);
|
|
this.logTime("Manager Setup", times);
|
|
await PluginManager.loadNewPlugins();
|
|
this.logTime("Loading new plugins", times);
|
|
this.addSettingTab(new PluginGroupSettings(this.app, this));
|
|
this.logTime("Creating the Settings Tab", times);
|
|
Manager.getInstance().updateStatusbarItem();
|
|
if (!Manager.getInstance().groupsMap) {
|
|
this.displayTimeNotice(times);
|
|
return;
|
|
}
|
|
if (Manager.getInstance().generateCommands) {
|
|
Manager.getInstance().groupsMap.forEach((group) => CommandManager.getInstance().AddGroupCommands(group.id));
|
|
if (Manager.getInstance().devLog) {
|
|
this.logTime("Generated Commands for Groups in", times);
|
|
}
|
|
}
|
|
if (window.performance.now() < disableStartupTimeout) {
|
|
Manager.getInstance().groupsMap.forEach((group) => {
|
|
if (group.loadAtStartup)
|
|
group.startup();
|
|
});
|
|
if (Manager.getInstance().devLog) {
|
|
this.logTime("Dispatching Groups for delayed start in", times);
|
|
}
|
|
}
|
|
this.displayTimeNotice(times);
|
|
}
|
|
logTime(label, times) {
|
|
if (Manager.getInstance().devLog) {
|
|
times.push({ label, time: this.elapsedTime(times) });
|
|
}
|
|
}
|
|
displayTimeNotice(times) {
|
|
if (!Manager.getInstance().devLog || times.length === 0) {
|
|
return;
|
|
}
|
|
const totalTime = Math.round(this.accTime(times.slice(1)));
|
|
new import_obsidian20.Notice(times.map((item) => item.label + ": " + item.time + " ms").join("\n") + "\nTotal Time: " + totalTime + " ms", 1e4);
|
|
}
|
|
elapsedTime(times) {
|
|
if (times.length > 1) {
|
|
return this.getCurrentTime() - this.accTime(times);
|
|
}
|
|
return this.getCurrentTime() - times[0].time;
|
|
}
|
|
accTime(times) {
|
|
return times.map((item) => item.time).reduce((prev, curr) => prev + curr);
|
|
}
|
|
getCurrentTime() {
|
|
return Date.now();
|
|
}
|
|
onunload() {
|
|
}
|
|
};
|