1515 lines
206 KiB
JavaScript
1515 lines
206 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);
|
||
|
|
||
|
// src/main.ts
|
||
|
var main_exports = {};
|
||
|
__export(main_exports, {
|
||
|
DEFAULT_SETTINGS: () => DEFAULT_SETTINGS,
|
||
|
default: () => DNPlugin
|
||
|
});
|
||
|
module.exports = __toCommonJS(main_exports);
|
||
|
var import_obsidian4 = require("obsidian");
|
||
|
|
||
|
// src/settings.ts
|
||
|
var import_obsidian = require("obsidian");
|
||
|
var DNSettingTab = class extends import_obsidian.PluginSettingTab {
|
||
|
constructor(app, plugin) {
|
||
|
super(app, plugin);
|
||
|
this.plugin = plugin;
|
||
|
}
|
||
|
display() {
|
||
|
const { containerEl } = this;
|
||
|
containerEl.empty();
|
||
|
new import_obsidian.Setting(containerEl).setName("Open dashboard navigator").addButton((btn) => {
|
||
|
btn.setButtonText("Open").setTooltip("Open dashboard navigator").onClick((evt) => {
|
||
|
this.plugin._DN_MODAL.open();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Default view").setDesc("Select view when opening window").addDropdown((sel) => {
|
||
|
this.dropdownDefaultView = sel;
|
||
|
sel.addOption("1", "Dashboard");
|
||
|
sel.addOption("2", "Navigator");
|
||
|
sel.onChange(async (val) => {
|
||
|
this.plugin.settings.default_view = parseInt(val);
|
||
|
this.plugin._DN_MODAL.default_view = this.plugin.settings.default_view;
|
||
|
await this.plugin.saveSettings();
|
||
|
}), sel.setValue(this.plugin.settings.default_view.toString());
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.dropdownDefaultView.setValue(DEFAULT_SETTINGS.default_view.toString());
|
||
|
this.plugin.settings.default_view = DEFAULT_SETTINGS.default_view;
|
||
|
this.plugin._DN_MODAL.default_view = this.plugin.settings.default_view;
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Navigator table layout").setDesc("Select table results layout").addDropdown((sel) => {
|
||
|
this.dropdownTableLayout = sel;
|
||
|
sel.addOption("dn-tbl-default", "Default");
|
||
|
sel.addOption("dn-tbl-row", "Row striped");
|
||
|
sel.addOption("dn-tbl-column", "Column striped");
|
||
|
sel.addOption("dn-tbl-bordered", "Bordered");
|
||
|
sel.onChange(async (val) => {
|
||
|
this.plugin.settings.selected_table_layout = val;
|
||
|
this.plugin._DN_MODAL.selected_table_layout = this.plugin.settings.selected_table_layout;
|
||
|
await this.plugin.saveSettings();
|
||
|
}), sel.setValue(this.plugin.settings.selected_table_layout.toString());
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.dropdownTableLayout.setValue(DEFAULT_SETTINGS.selected_table_layout.toString());
|
||
|
this.plugin.settings.selected_table_layout = DEFAULT_SETTINGS.selected_table_layout;
|
||
|
this.plugin._DN_MODAL.selected_table_layout = this.plugin.settings.selected_table_layout;
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Date format").setDesc("Select date format").addDropdown((sel) => {
|
||
|
this.dropdownDateFormat = sel;
|
||
|
sel.addOption("YYYY-MM-DD HH:mm:ss", "YYYY-MM-DD HH:mm:ss");
|
||
|
sel.addOption("YYYY-MM-DD HH:mm", "YYYY-MM-DD HH:mm");
|
||
|
sel.addOption("YYYY-MM-DD", "YYYY-MM-DD");
|
||
|
sel.addOption("DD/MM/YYYY HH:mm:ss", "DD/MM/YYYY HH:mm:ss");
|
||
|
sel.addOption("DD/MM/YYYY HH:mm", "DD/MM/YYYY HH:mm");
|
||
|
sel.addOption("DD/MM/YYYY", "DD/MM/YYYY");
|
||
|
sel.onChange(async (val) => {
|
||
|
this.plugin.settings.date_format = val;
|
||
|
this.plugin._DN_MODAL.date_format = this.plugin.settings.date_format;
|
||
|
await this.plugin.saveSettings();
|
||
|
}), sel.setValue(this.plugin.settings.date_format.toString());
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.dropdownDateFormat.setValue(DEFAULT_SETTINGS.date_format.toString());
|
||
|
this.plugin.settings.date_format = DEFAULT_SETTINGS.date_format;
|
||
|
this.plugin._DN_MODAL.date_format = this.plugin.settings.date_format;
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Font size").setDesc("Select font size in pixels for results and links").addSlider((sli) => {
|
||
|
this.sliderFontSize = sli;
|
||
|
let slider_val;
|
||
|
if (this.plugin.settings.font_size) {
|
||
|
slider_val = this.plugin.settings.font_size;
|
||
|
} else {
|
||
|
slider_val = DEFAULT_SETTINGS.font_size;
|
||
|
}
|
||
|
sli.setDynamicTooltip();
|
||
|
sli.setLimits(12, 24, 1);
|
||
|
sli.setValue(slider_val);
|
||
|
sli.onChange((val) => {
|
||
|
this.plugin.settings.font_size = val;
|
||
|
this.plugin.dnSetFontSize(val);
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.sliderFontSize.setValue(DEFAULT_SETTINGS.font_size);
|
||
|
this.plugin.settings.font_size = DEFAULT_SETTINGS.font_size;
|
||
|
this.plugin.dnSetFontSize(this.plugin.settings.font_size);
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Files per page").setDesc("Number of results per page").addDropdown((sel) => {
|
||
|
this.dropdownFilesPerPage = sel;
|
||
|
sel.addOption("10", "10");
|
||
|
sel.addOption("20", "20");
|
||
|
sel.addOption("30", "30");
|
||
|
sel.addOption("50", "50");
|
||
|
sel.addOption("100", "100");
|
||
|
sel.onChange(async (val) => {
|
||
|
this.plugin.settings.files_per_page = parseInt(val);
|
||
|
this.plugin._DN_MODAL.files_per_page = this.plugin.settings.files_per_page;
|
||
|
await this.plugin.saveSettings();
|
||
|
}), sel.setValue(this.plugin.settings.files_per_page.toString());
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.dropdownFilesPerPage.setValue(DEFAULT_SETTINGS.files_per_page.toString());
|
||
|
this.plugin.settings.files_per_page = DEFAULT_SETTINGS.files_per_page;
|
||
|
this.plugin._DN_MODAL.files_per_page = this.plugin.settings.files_per_page;
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Recent files").setDesc("Number of recent files per category").addDropdown((sel) => {
|
||
|
this.dropdownRecentFiles = sel;
|
||
|
sel.addOption("3", "3");
|
||
|
sel.addOption("4", "4");
|
||
|
sel.addOption("5", "5");
|
||
|
sel.addOption("10", "10");
|
||
|
sel.onChange(async (val) => {
|
||
|
this.plugin.settings.num_recent_files = parseInt(val);
|
||
|
this.plugin._DN_MODAL.num_recent_files = this.plugin.settings.num_recent_files;
|
||
|
await this.plugin.saveSettings();
|
||
|
}), sel.setValue(this.plugin.settings.num_recent_files.toString());
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.dropdownRecentFiles.setValue(DEFAULT_SETTINGS.num_recent_files.toString());
|
||
|
this.plugin.settings.num_recent_files = DEFAULT_SETTINGS.num_recent_files;
|
||
|
this.plugin._DN_MODAL.num_recent_files = this.plugin.settings.num_recent_files;
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Excluded file extensions").setDesc("File extensions to exclude, separated by commas").addText((text) => {
|
||
|
this.textExcludedExtensions = text;
|
||
|
text.setPlaceholder("File extensions to exclude").setValue(this.plugin.settings.excluded_ext).onChange(async (val) => {
|
||
|
this.plugin.settings.excluded_ext = val;
|
||
|
this.plugin._DN_MODAL.excluded_extensions = this.plugin.dnGetExcludedExtensions(val);
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.textExcludedExtensions.setValue("");
|
||
|
this.plugin.settings.excluded_ext = "";
|
||
|
this.plugin._DN_MODAL.excluded_extensions = [];
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Excluded folders").setDesc("List of folder paths to exclude, separated by commas").addText((text) => {
|
||
|
this.textExcludedFolders = text;
|
||
|
text.setPlaceholder("Folder paths to exclude").setValue(this.plugin.settings.excluded_path).onChange(async (val) => {
|
||
|
this.plugin.settings.excluded_path = val;
|
||
|
this.plugin._DN_MODAL.excluded_folders = this.plugin.dnGetExcludedFolders(val);
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.textExcludedFolders.setValue("");
|
||
|
this.plugin.settings.excluded_path = "";
|
||
|
this.plugin._DN_MODAL.excluded_folders = [];
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Toggle colored files").setDesc("Turn on/off colored files").addToggle((toggle) => {
|
||
|
this.toggleColoredFiles = toggle;
|
||
|
toggle.setValue(this.plugin.settings.colored_files).onChange(async (val) => {
|
||
|
this.plugin.settings.colored_files = val;
|
||
|
this.plugin._DN_MODAL.colored_files = val;
|
||
|
this.plugin._DN_MODAL.dnToggleColoredFiles();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.toggleColoredFiles.setValue(DEFAULT_SETTINGS.colored_files);
|
||
|
this.plugin.settings.colored_files = DEFAULT_SETTINGS.colored_files;
|
||
|
this.plugin._DN_MODAL.colored_files = DEFAULT_SETTINGS.colored_files;
|
||
|
this.plugin._DN_MODAL.dnToggleColoredFiles();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: Notes").setDesc("Color of notes").addColorPicker((color) => {
|
||
|
this.colorCompNotes = color;
|
||
|
color.setValue(this.plugin.settings.color_notes).onChange(async (val) => {
|
||
|
this.plugin.settings.color_notes = val;
|
||
|
this.plugin._DN_MODAL.color_notes = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompNotes.setValue(DEFAULT_SETTINGS.color_notes);
|
||
|
this.plugin.settings.color_notes = DEFAULT_SETTINGS.color_notes;
|
||
|
this.plugin._DN_MODAL.color_notes = DEFAULT_SETTINGS.color_notes;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: Canvas").setDesc("Color of canvas").addColorPicker((color) => {
|
||
|
this.colorCompCanvas = color;
|
||
|
color.setValue(this.plugin.settings.color_canvas).onChange(async (val) => {
|
||
|
this.plugin.settings.color_canvas = val;
|
||
|
this.plugin._DN_MODAL.color_canvas = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompCanvas.setValue(DEFAULT_SETTINGS.color_canvas);
|
||
|
this.plugin.settings.color_canvas = DEFAULT_SETTINGS.color_canvas;
|
||
|
this.plugin._DN_MODAL.color_canvas = DEFAULT_SETTINGS.color_canvas;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: Images").setDesc("Color of images").addColorPicker((color) => {
|
||
|
this.colorCompImages = color;
|
||
|
color.setValue(this.plugin.settings.color_images).onChange(async (val) => {
|
||
|
this.plugin.settings.color_images = val;
|
||
|
this.plugin._DN_MODAL.color_images = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompImages.setValue(DEFAULT_SETTINGS.color_images);
|
||
|
this.plugin.settings.color_images = DEFAULT_SETTINGS.color_images;
|
||
|
this.plugin._DN_MODAL.color_images = DEFAULT_SETTINGS.color_images;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: Videos").setDesc("Color of videos").addColorPicker((color) => {
|
||
|
this.colorCompVideos = color;
|
||
|
color.setValue(this.plugin.settings.color_videos).onChange(async (val) => {
|
||
|
this.plugin.settings.color_videos = val;
|
||
|
this.plugin._DN_MODAL.color_videos = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompVideos.setValue(DEFAULT_SETTINGS.color_videos);
|
||
|
this.plugin.settings.color_videos = DEFAULT_SETTINGS.color_videos;
|
||
|
this.plugin._DN_MODAL.color_videos = DEFAULT_SETTINGS.color_videos;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: Audios").setDesc("Color of audios").addColorPicker((color) => {
|
||
|
this.colorCompAudios = color;
|
||
|
color.setValue(this.plugin.settings.color_audios).onChange(async (val) => {
|
||
|
this.plugin.settings.color_audios = val;
|
||
|
this.plugin._DN_MODAL.color_audios = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompAudios.setValue(DEFAULT_SETTINGS.color_audios);
|
||
|
this.plugin.settings.color_audios = DEFAULT_SETTINGS.color_audios;
|
||
|
this.plugin._DN_MODAL.color_audios = DEFAULT_SETTINGS.color_audios;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: PDF").setDesc("Color of PDF files").addColorPicker((color) => {
|
||
|
this.colorCompPdf = color;
|
||
|
color.setValue(this.plugin.settings.color_pdf).onChange(async (val) => {
|
||
|
this.plugin.settings.color_pdf = val;
|
||
|
this.plugin._DN_MODAL.color_pdf = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompPdf.setValue(DEFAULT_SETTINGS.color_pdf);
|
||
|
this.plugin.settings.color_pdf = DEFAULT_SETTINGS.color_pdf;
|
||
|
this.plugin._DN_MODAL.color_pdf = DEFAULT_SETTINGS.color_pdf;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
new import_obsidian.Setting(containerEl).setName("Color: Other files").setDesc("Color of other files").addColorPicker((color) => {
|
||
|
this.colorCompOther = color;
|
||
|
color.setValue(this.plugin.settings.color_other).onChange(async (val) => {
|
||
|
this.plugin.settings.color_other = val;
|
||
|
this.plugin._DN_MODAL.color_other = val;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
await this.plugin.saveSettings();
|
||
|
});
|
||
|
}).addExtraButton((btn) => {
|
||
|
btn.setIcon("rotate-ccw");
|
||
|
btn.setTooltip("Restore default");
|
||
|
btn.onClick(() => {
|
||
|
this.colorCompOther.setValue(DEFAULT_SETTINGS.color_other);
|
||
|
this.plugin.settings.color_other = DEFAULT_SETTINGS.color_other;
|
||
|
this.plugin._DN_MODAL.color_other = DEFAULT_SETTINGS.color_other;
|
||
|
this.plugin._DN_MODAL.dnSetCustomColors();
|
||
|
this.plugin.saveSettings();
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// src/dn.ts
|
||
|
var import_obsidian2 = require("obsidian");
|
||
|
|
||
|
// src/utils/format.ts
|
||
|
function formatFileSize(fileSize) {
|
||
|
if (fileSize === 0) {
|
||
|
return "0";
|
||
|
}
|
||
|
const formattedSize = fileSize.toFixed(0).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||
|
return formattedSize;
|
||
|
}
|
||
|
function getFolderStructure(folder) {
|
||
|
const folders = folder.split("/").slice(0, -1);
|
||
|
if (folders.length === 0) {
|
||
|
return "/";
|
||
|
}
|
||
|
return "/" + folders.join("/");
|
||
|
}
|
||
|
|
||
|
// src/utils/piechart.ts
|
||
|
var DNPieChart = class {
|
||
|
constructor(canvas, margin = 10, fontSize = 12, legendWidth = 50, labelColor = "#828282") {
|
||
|
this._canvas = canvas;
|
||
|
this._ctx = canvas.getContext("2d");
|
||
|
this._data = [];
|
||
|
this._margin = margin;
|
||
|
this._fontSize = fontSize;
|
||
|
this._legendWidth = legendWidth;
|
||
|
this._labelColor = labelColor;
|
||
|
}
|
||
|
addData(value, color, label) {
|
||
|
this._data.push({ value, color, label });
|
||
|
}
|
||
|
draw() {
|
||
|
const { width, height } = this._canvas;
|
||
|
const availWidth = width - 2 * this._margin;
|
||
|
const availHeight = height - 2 * this._margin;
|
||
|
const scale = Math.min(availWidth / width, availHeight / height);
|
||
|
const radius = Math.min(availWidth, availHeight) / 2 * scale;
|
||
|
this._cX = width / 2;
|
||
|
this._cY = height / 2;
|
||
|
this._ctx.clearRect(0, 0, width, height);
|
||
|
const totalValue = this._data.reduce((acc, curr) => acc + curr.value, 0);
|
||
|
let currentAngle = -Math.PI / 2;
|
||
|
this._data.forEach((slice) => {
|
||
|
const sliceAngle = slice.value / totalValue * 2 * Math.PI;
|
||
|
this.drawSlice(radius, sliceAngle, slice.color, currentAngle);
|
||
|
currentAngle += sliceAngle;
|
||
|
});
|
||
|
this.drawLegend(2, 20);
|
||
|
}
|
||
|
drawSlice(radius, sliceAngle, color, startAngle) {
|
||
|
this._ctx.beginPath();
|
||
|
this._ctx.arc(this._cX, this._cY, radius, startAngle, startAngle + sliceAngle);
|
||
|
this._ctx.lineTo(this._cX, this._cY);
|
||
|
this._ctx.fillStyle = color;
|
||
|
this._ctx.closePath();
|
||
|
this._ctx.fill();
|
||
|
}
|
||
|
drawLegend(x, y) {
|
||
|
const lineHeight = this._fontSize + 5;
|
||
|
this._data.forEach((slice, index) => {
|
||
|
const textX = x + this._legendWidth / 5;
|
||
|
const textY = y + index * lineHeight - 10;
|
||
|
this._ctx.fillStyle = slice.color;
|
||
|
this._ctx.fillRect(textX - 10, textY, 5, 5);
|
||
|
this._ctx.fillStyle = this._labelColor;
|
||
|
this._ctx.font = `${this._fontSize}px sans-serif`;
|
||
|
this._ctx.fillText(`${slice.label} (${slice.value})`, textX, textY + 8);
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// src/dn.ts
|
||
|
var import_obsidian3 = require("obsidian");
|
||
|
var DNModal = class extends import_obsidian2.Modal {
|
||
|
constructor(app) {
|
||
|
super(app);
|
||
|
this._sort_order = "desc";
|
||
|
this._sort_column = "modified";
|
||
|
this._selected_category = "";
|
||
|
this._TABLE_LAYOUTS = ["dn-tbl-default", "dn-tbl-row", "dn-tbl-column", "dn-tbl-bordered"];
|
||
|
this.selected_table_layout = "dn-tbl-default";
|
||
|
this.selected_sort_value = "modified-desc";
|
||
|
this.num_recent_files = 5;
|
||
|
this.files_per_page = 20;
|
||
|
this.date_format = "YYYY-MM-DD HH:mm";
|
||
|
this.default_view = 1;
|
||
|
this.excluded_extensions = [];
|
||
|
this.excluded_folders = [];
|
||
|
// File colors
|
||
|
this.color_notes = "#bf48ff";
|
||
|
this.color_images = "#007fff";
|
||
|
this.color_canvas = "#ff7f28";
|
||
|
this.color_videos = "#d34848";
|
||
|
this.color_audios = "#bfbf00";
|
||
|
this.color_pdf = "#00a300";
|
||
|
this.color_other = "#828282";
|
||
|
this.colored_files = false;
|
||
|
this.dnHandleIntersection = (entries) => {
|
||
|
entries.forEach((entry) => {
|
||
|
if (!entry.isIntersecting) {
|
||
|
entry.target.removeEventListener("contextmenu", this.dnHandleClick);
|
||
|
entry.target.removeEventListener("click", this.dnHandleClick);
|
||
|
entry.target.removeEventListener("dblclick", this.dnHandleDblClick);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
this.intersectionObserver = new IntersectionObserver(this.dnHandleIntersection);
|
||
|
}
|
||
|
async onOpen() {
|
||
|
var _a;
|
||
|
const { contentEl } = this;
|
||
|
this._files = [];
|
||
|
this._folders = [];
|
||
|
this._notes = [];
|
||
|
this._recent = [];
|
||
|
this._images = [];
|
||
|
this._canvas = [];
|
||
|
this._audios = [];
|
||
|
this._videos = [];
|
||
|
this._pdf = [];
|
||
|
this._other = [];
|
||
|
const leaf = (_a = this.app.workspace) == null ? void 0 : _a.getMostRecentLeaf();
|
||
|
if (leaf !== null) {
|
||
|
this._leaf = leaf;
|
||
|
}
|
||
|
const dnFilesAndFolders = this.app.vault.getAllLoadedFiles();
|
||
|
for (const absF of dnFilesAndFolders) {
|
||
|
if (absF instanceof import_obsidian2.TFile) {
|
||
|
this._files.push(absF);
|
||
|
} else if (absF instanceof import_obsidian2.TFolder && !absF.isRoot()) {
|
||
|
this._folders.push(absF);
|
||
|
}
|
||
|
}
|
||
|
this._filtered_files = this._files.filter(
|
||
|
(file) => {
|
||
|
return !this.excluded_extensions.includes(file.extension.toLowerCase()) && !this.excluded_folders.some((folder) => file.path.startsWith(folder));
|
||
|
}
|
||
|
);
|
||
|
this._files = this._filtered_files;
|
||
|
await this.dnOrganizeFiles({ arr: this._filtered_files });
|
||
|
this._recent = await this.dnGetRecentFiles(this._filtered_files);
|
||
|
this.dnCreateMainUI(contentEl);
|
||
|
this.dnSetView(this.default_view);
|
||
|
this.dnSetSelectLayoutValue(this.selected_table_layout);
|
||
|
this.dnSetSelectSortValue(this.selected_sort_value);
|
||
|
this.dnToggleColoredFiles();
|
||
|
}
|
||
|
dnSetCustomColors() {
|
||
|
document.body.style.setProperty("--dn-notes-color", this.color_notes);
|
||
|
document.body.style.setProperty("--dn-images-color", this.color_images);
|
||
|
document.body.style.setProperty("--dn-canvas-color", this.color_canvas);
|
||
|
document.body.style.setProperty("--dn-videos-color", this.color_videos);
|
||
|
document.body.style.setProperty("--dn-audios-color", this.color_audios);
|
||
|
document.body.style.setProperty("--dn-pdfs-color", this.color_pdf);
|
||
|
document.body.style.setProperty("--dn-other-color", this.color_other);
|
||
|
}
|
||
|
dnToggleColoredFiles() {
|
||
|
const dnMainContainer = document.getElementById("dn-container");
|
||
|
if (this.colored_files) {
|
||
|
dnMainContainer == null ? void 0 : dnMainContainer.classList.add("dn-colored-files");
|
||
|
} else {
|
||
|
dnMainContainer == null ? void 0 : dnMainContainer.classList.remove("dn-colored-files");
|
||
|
}
|
||
|
this.dnSetCustomColors();
|
||
|
}
|
||
|
async dnCreateMainUI(el) {
|
||
|
const mainContainer = el.createEl("div", { cls: "dn-container" });
|
||
|
mainContainer.setAttribute("id", "dn-container");
|
||
|
this.dnCreateInputSearch(mainContainer);
|
||
|
const topNav = mainContainer.createEl("div", { cls: "dn-top-nav" });
|
||
|
const leftTopNav = topNav.createEl("div");
|
||
|
const rightTopNav = topNav.createEl("div");
|
||
|
this._BTN_DASHBOARD = leftTopNav.createEl("button", { text: "Dashboard", cls: "mod-cta" });
|
||
|
this._BTN_DASHBOARD.onClickEvent((evt) => {
|
||
|
this.dnSetView(1);
|
||
|
});
|
||
|
this._BTN_NAVIGATOR = leftTopNav.createEl("button", { text: "Navigator" });
|
||
|
this._BTN_NAVIGATOR.onClickEvent((evt) => {
|
||
|
this.dnSearchVault(this._INPUT_SEARCH.value);
|
||
|
this.dnSetView(2);
|
||
|
});
|
||
|
this.labelLayout = rightTopNav.createEl("span", {
|
||
|
text: "Layout:",
|
||
|
cls: "dn-tbl-label"
|
||
|
});
|
||
|
this.labelLayout.setAttribute("id", "dn-label-layout");
|
||
|
this._SELECT_TABLE_LAYOUT = rightTopNav.createEl("select", {
|
||
|
cls: "dropdown tbl-select"
|
||
|
});
|
||
|
this._SELECT_TABLE_LAYOUT.createEl("option", { text: "Default", value: "dn-tbl-default" });
|
||
|
this._SELECT_TABLE_LAYOUT.createEl("option", { text: "Row striped", value: "dn-tbl-row" });
|
||
|
this._SELECT_TABLE_LAYOUT.createEl("option", { text: "Column striped", value: "dn-tbl-column" });
|
||
|
this._SELECT_TABLE_LAYOUT.createEl("option", { text: "Bordered", value: "dn-tbl-bordered" });
|
||
|
this._SELECT_TABLE_LAYOUT.addEventListener("change", () => {
|
||
|
this.dnSelectTableLayout();
|
||
|
});
|
||
|
this.labelSort = rightTopNav.createEl("span", {
|
||
|
text: "Sort by:",
|
||
|
cls: "dn-tbl-label"
|
||
|
});
|
||
|
this.labelSort.setAttribute("id", "dn-label-sort");
|
||
|
this._SELECT_SORT = rightTopNav.createEl("select", {
|
||
|
cls: "dropdown"
|
||
|
});
|
||
|
this._SELECT_SORT.setAttribute("id", "dn-select-sort");
|
||
|
this._SELECT_SORT.addEventListener("change", () => {
|
||
|
this.dnSortColumnWithSelect();
|
||
|
});
|
||
|
const option1 = this._SELECT_SORT.createEl("option", { text: "File name (A to Z)", value: "name-asc" });
|
||
|
const option2 = this._SELECT_SORT.createEl("option", { text: "File name (Z to A)", value: "name-desc" });
|
||
|
const option3 = this._SELECT_SORT.createEl("option", { text: "Path (A to Z)", value: "path-asc" });
|
||
|
const option4 = this._SELECT_SORT.createEl("option", { text: "Path (Z to A)", value: "path-desc" });
|
||
|
const option5 = this._SELECT_SORT.createEl("option", { text: "File size (smallest to largest)", value: "size-asc" });
|
||
|
const option6 = this._SELECT_SORT.createEl("option", { text: "File size (largest to smallest)", value: "size-desc" });
|
||
|
const option7 = this._SELECT_SORT.createEl("option", { text: "Date/time (oldest to newest)", value: "modified-asc" });
|
||
|
const option8 = this._SELECT_SORT.createEl("option", { text: "Date/time (newest to oldest)", value: "modified-desc" });
|
||
|
this._VIEW_DASHBOARD = mainContainer.createEl("div", { cls: "dn-flex" });
|
||
|
this._VIEW_NAVIGATOR = mainContainer.createEl("div", { cls: "dn-display-none" });
|
||
|
this._divSearchResults = this._VIEW_NAVIGATOR.createEl("div", { cls: "dn-div-table" });
|
||
|
this.dnShowSearchResults({ f: this._filtered_files, el: this._divSearchResults, leaf: this._leaf });
|
||
|
const divVaultStats = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divVaultStats.setAttribute("id", "dn-vault-stats");
|
||
|
const divVaultGraph = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divVaultGraph.setAttribute("id", "dn-vault-graph");
|
||
|
const divRecentFiles = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divRecentFiles.setAttribute("id", "dn-recent-files");
|
||
|
const divRecentNotes = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divRecentNotes.setAttribute("id", "dn-recent-notes");
|
||
|
;
|
||
|
const divCanvas = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divCanvas.setAttribute("id", "dn-canvas");
|
||
|
const divImages = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divImages.setAttribute("id", "dn-images");
|
||
|
const divAudios = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divAudios.setAttribute("id", "dn-audios");
|
||
|
const divVideos = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divVideos.setAttribute("id", "dn-videos");
|
||
|
const divPDFs = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divPDFs.setAttribute("id", "dn-pdfs");
|
||
|
const divOther = this._VIEW_DASHBOARD.createEl("div");
|
||
|
divOther.setAttribute("id", "dn-other");
|
||
|
const btnNotes = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-notes",
|
||
|
"Notes",
|
||
|
this._notes,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const btnCanvas = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-canvas",
|
||
|
"Canvas",
|
||
|
this._canvas,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const btnImages = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-images",
|
||
|
"Images",
|
||
|
this._images,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const btnAudios = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-audios",
|
||
|
"Audios",
|
||
|
this._audios,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const btnVideos = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-videos",
|
||
|
"Videos",
|
||
|
this._videos,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const btnPDF = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-pdf",
|
||
|
"PDF",
|
||
|
this._pdf,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const btnOther = await this.dnCreateBtn(
|
||
|
divVaultStats,
|
||
|
"dn-btn-other",
|
||
|
"Other",
|
||
|
this._other,
|
||
|
this._divSearchResults,
|
||
|
this._leaf
|
||
|
);
|
||
|
const canvasPieChart1 = divVaultGraph.createEl("canvas");
|
||
|
canvasPieChart1.setAttribute("id", "dashboard-canvas");
|
||
|
const styles = getComputedStyle(document.body);
|
||
|
const labelColor = styles.getPropertyValue("--text-muted");
|
||
|
const pieChart1 = new DNPieChart(canvasPieChart1, 10, 12, 50, labelColor);
|
||
|
pieChart1.addData(this._notes.length, this.color_notes, "Notes");
|
||
|
pieChart1.addData(this._images.length, this.color_images, "Images");
|
||
|
pieChart1.addData(this._canvas.length, this.color_canvas, "Canvas");
|
||
|
pieChart1.addData(this._videos.length, this.color_videos, "Videos");
|
||
|
pieChart1.addData(this._audios.length, this.color_audios, "Audios");
|
||
|
pieChart1.addData(this._pdf.length, this.color_pdf, "PDF");
|
||
|
pieChart1.addData(this._other.length, this.color_other, "Other");
|
||
|
pieChart1.draw();
|
||
|
const divStatsFrame = divVaultGraph.createEl("div", { cls: "dn-stats-files-folders" });
|
||
|
divStatsFrame.createEl("div", { cls: "dn-stats-files", text: "Files: " + this._filtered_files.length });
|
||
|
divStatsFrame.createEl("div", { cls: "dn-stats-folders", text: "Folders: " + this._folders.length });
|
||
|
await this.dnCreateRecentFiles("Recent files", divRecentFiles, this._recent, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent notes", divRecentNotes, this._notes, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent canvas", divCanvas, this._canvas, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent images", divImages, this._images, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent audios", divAudios, this._audios, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent videos", divVideos, this._videos, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent PDFs", divPDFs, this._pdf, this.num_recent_files);
|
||
|
await this.dnCreateRecentFiles("Recent other files", divOther, this._other, this.num_recent_files);
|
||
|
}
|
||
|
async dnCreateBtn(elDiv, btnId, btnTitle, btnCategoryFiles, displayEl, leaf) {
|
||
|
let btn = elDiv.createEl("div", { cls: "dn-btn-stats" });
|
||
|
btn.setAttribute("id", btnId);
|
||
|
btn.createEl("span", { cls: "dn-btn-stats-label", text: btnTitle });
|
||
|
btn.createEl("span", { cls: "dn-btn-stats-icon" });
|
||
|
btn.createEl("span", { cls: "dn-btn-stats-number", text: btnCategoryFiles.length.toString() });
|
||
|
btn.onClickEvent((evt) => {
|
||
|
this._filtered_files = btnCategoryFiles;
|
||
|
this._selected_category = " (" + btnTitle + ")";
|
||
|
this.dnSortFilteredFiles(false);
|
||
|
this.dnShowSearchResults({ f: btnCategoryFiles, el: displayEl, leaf });
|
||
|
this.dnSetView(2);
|
||
|
});
|
||
|
return btn;
|
||
|
}
|
||
|
async dnCreateRecentFiles(title, divF, files, num_files) {
|
||
|
if (files.length === 0) {
|
||
|
divF.createEl("h3", { cls: "dn-subtitles", text: title });
|
||
|
divF.createEl("p", { cls: "dn-no-results-found", text: "No files found." });
|
||
|
divF.classList.add("dn-display-none");
|
||
|
} else {
|
||
|
divF.createEl("h3", { cls: "dn-subtitles", text: title });
|
||
|
const sortedFiles = await this.dnGetRecentFiles(files);
|
||
|
sortedFiles.forEach((sfile) => {
|
||
|
divF.createEl("a", { cls: this.dnSetFileIconClass(sfile.extension), text: sfile.basename, title: sfile.path }).onClickEvent((evt) => {
|
||
|
if (sfile !== null) {
|
||
|
this.dnOpenFileAlt(sfile, evt);
|
||
|
}
|
||
|
});
|
||
|
if (sfile.extension !== "md") {
|
||
|
divF.createEl("span", { cls: "nav-file-tag", text: sfile.extension });
|
||
|
}
|
||
|
divF.createEl("br");
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
dnCreateInputSearch(el) {
|
||
|
const searchContainer = el.createEl("div", { cls: "dn-search-input-container" });
|
||
|
this._INPUT_SEARCH = searchContainer.createEl("input", { type: "search", placeholder: "Search..." });
|
||
|
this._INPUT_SEARCH.setAttribute("id", "dn-input-filter");
|
||
|
this._INPUT_SEARCH.spellcheck = false;
|
||
|
this._INPUT_SEARCH.focus();
|
||
|
const clearInputSearch = searchContainer.createEl("div", { cls: "search-input-clear-button" }).onClickEvent((evt) => {
|
||
|
this._INPUT_SEARCH.value = "";
|
||
|
this._INPUT_SEARCH.focus();
|
||
|
this.dnSearchVault(this._INPUT_SEARCH.value);
|
||
|
});
|
||
|
this._INPUT_SEARCH.addEventListener("input", (0, import_obsidian2.debounce)(() => this.dnSearchVault(this._INPUT_SEARCH.value), 300, true));
|
||
|
}
|
||
|
async dnSearchVault(val) {
|
||
|
let rExp;
|
||
|
try {
|
||
|
rExp = new RegExp(val.toLowerCase(), "iu");
|
||
|
} catch (error) {
|
||
|
return;
|
||
|
}
|
||
|
this.dnSetView(2);
|
||
|
const isDateSearch = val.startsWith("@");
|
||
|
if (isDateSearch) {
|
||
|
this._INPUT_SEARCH.classList.add("dn-input-datesearch");
|
||
|
} else {
|
||
|
this._INPUT_SEARCH.classList.remove("dn-input-datesearch");
|
||
|
}
|
||
|
this._filtered_files = this._files.filter(
|
||
|
(file) => {
|
||
|
if (isDateSearch) {
|
||
|
let mtime = (0, import_obsidian3.moment)(file.stat.mtime);
|
||
|
const dateSearch = val.slice(1).toLowerCase().split(" ");
|
||
|
switch (dateSearch[0]) {
|
||
|
case "day":
|
||
|
case "today":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)(), "day");
|
||
|
case "day-1":
|
||
|
case "yesterday":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(1, "days"), "day");
|
||
|
case "day-2":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(2, "days"), "day");
|
||
|
case "day-3":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(3, "days"), "day");
|
||
|
case "day-4":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(4, "days"), "day");
|
||
|
case "day-5":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(5, "days"), "day");
|
||
|
case "day-6":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(6, "days"), "day");
|
||
|
case "day-7":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)().subtract(7, "days"), "day");
|
||
|
case "week":
|
||
|
return mtime.isBetween((0, import_obsidian3.moment)().subtract(7, "days"), (0, import_obsidian3.moment)(), "day", "[]");
|
||
|
case "month":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)(), "month");
|
||
|
case "year":
|
||
|
return mtime.isSame((0, import_obsidian3.moment)(), "year");
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
} else {
|
||
|
return rExp.test(file.name.toLowerCase()) || rExp.test(getFolderStructure(file.path).toLowerCase()) || rExp.test((0, import_obsidian3.moment)(file.stat.mtime).format(this.date_format)) || rExp.test(this.dnGetTagsPerFile(file).toLowerCase());
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
this._selected_category = "";
|
||
|
this.dnSortFilteredFiles(false);
|
||
|
await this.dnShowSearchResults({ f: this._filtered_files, el: this._divSearchResults, leaf: this._leaf });
|
||
|
const tbody = document.getElementById("dn-table-results");
|
||
|
if (tbody !== null) {
|
||
|
const tr = tbody.getElementsByTagName("tr");
|
||
|
for (let i = 0, len = tr.length; i < len; i++) {
|
||
|
const allTds = tr[i].querySelectorAll("td");
|
||
|
let isResult = false;
|
||
|
for (let j = 0; j < allTds.length; j++) {
|
||
|
const td = allTds[j];
|
||
|
const tdVal = td.innerText.toLowerCase();
|
||
|
if (rExp.test(tdVal) || isDateSearch) {
|
||
|
isResult = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (isResult) {
|
||
|
tr[i].classList.remove("dn-display-none");
|
||
|
} else {
|
||
|
tr[i].classList.add("dn-display-none");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
async dnSortFilteredFiles(toggle) {
|
||
|
switch (this._sort_column) {
|
||
|
case "name":
|
||
|
case "path":
|
||
|
this.dnSortColumnString(this._sort_column, this._sort_order, toggle);
|
||
|
break;
|
||
|
case "size":
|
||
|
case "modified":
|
||
|
this.dnSortColumnNumber(this._sort_column, this._sort_order, toggle);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
dnSortColumnWithSelect() {
|
||
|
const val = this._SELECT_SORT.value;
|
||
|
if (this.dnIsValidSort(val)) {
|
||
|
const selSort = val.split("-");
|
||
|
this._sort_column = selSort[0];
|
||
|
this._sort_order = selSort[1];
|
||
|
switch (this._sort_column) {
|
||
|
case "name":
|
||
|
case "path":
|
||
|
this.dnSortColumnString(this._sort_column, this._sort_order, false);
|
||
|
break;
|
||
|
case "size":
|
||
|
case "modified":
|
||
|
this.dnSortColumnNumber(this._sort_column, this._sort_order, false);
|
||
|
break;
|
||
|
}
|
||
|
this.dnShowSearchResults({ f: this._filtered_files, el: this._divSearchResults, leaf: this._leaf });
|
||
|
}
|
||
|
}
|
||
|
dnIsValidSort(val) {
|
||
|
if ([
|
||
|
"name-asc",
|
||
|
"name-desc",
|
||
|
"path-asc",
|
||
|
"path-desc",
|
||
|
"size-asc",
|
||
|
"size-desc",
|
||
|
"modified-asc",
|
||
|
"modified-desc"
|
||
|
].includes(val)) {
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
dnIsValidLayout(val) {
|
||
|
if (this._TABLE_LAYOUTS.includes(val)) {
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
async dnShowSearchResults({ f, el, leaf, currentPage = 1 }) {
|
||
|
el.empty();
|
||
|
const paginationContainer = this._divSearchResults.createEl("div", { cls: "dn-pagination" });
|
||
|
const table = el.createEl("table", { cls: this.selected_table_layout });
|
||
|
table.setAttribute("id", "dn-table");
|
||
|
const thead = table.createEl("thead");
|
||
|
const tr = thead.createEl("tr");
|
||
|
this._th1 = tr.createEl("th", { text: "Name" });
|
||
|
this._th2 = tr.createEl("th", { text: "Path" });
|
||
|
this._th3 = tr.createEl("th", { text: "Size" });
|
||
|
this._th4 = tr.createEl("th", { text: "Date" });
|
||
|
this._th5 = tr.createEl("th", { text: "Tags" });
|
||
|
this._th1.addEventListener("dblclick", () => this.dnAlternateSortColumn("name"));
|
||
|
this._th2.addEventListener("dblclick", () => this.dnAlternateSortColumn("path"));
|
||
|
this._th3.addEventListener("dblclick", () => this.dnAlternateSortColumn("size"));
|
||
|
this._th4.addEventListener("dblclick", () => this.dnAlternateSortColumn("modified"));
|
||
|
const tbody = table.createEl("tbody");
|
||
|
tbody.setAttribute("id", "dn-table-results");
|
||
|
if (f.length > 0) {
|
||
|
if (this.intersectionObserver) {
|
||
|
this.intersectionObserver.disconnect();
|
||
|
}
|
||
|
this._total_pages = Math.ceil(f.length / this.files_per_page);
|
||
|
const paginatedData = f.slice((currentPage - 1) * this.files_per_page, currentPage * this.files_per_page);
|
||
|
paginatedData.forEach(async (file) => {
|
||
|
let tr2 = tbody.createEl("tr");
|
||
|
tr2.addEventListener("contextmenu", (evt) => {
|
||
|
this.dnHandleClick(evt, file);
|
||
|
});
|
||
|
tr2.addEventListener("click", (evt) => {
|
||
|
this.dnHandleClick(evt, file);
|
||
|
});
|
||
|
tr2.addEventListener("dblclick", (evt) => {
|
||
|
this.dnHandleDblClick(evt, file);
|
||
|
});
|
||
|
this.intersectionObserver.observe(tr2);
|
||
|
let td1 = tr2.createEl("td");
|
||
|
let td1Link = td1.createEl("a", { cls: this.dnSetFileIconClass(file.extension), text: file.name }).onClickEvent((evt) => {
|
||
|
if (leaf !== null && file !== null) {
|
||
|
this.dnOpenFileAlt(file, evt);
|
||
|
}
|
||
|
});
|
||
|
let fSize = formatFileSize(file.stat.size);
|
||
|
let fMTime = (0, import_obsidian3.moment)(file.stat.mtime).format(this.date_format);
|
||
|
let td2 = tr2.createEl("td");
|
||
|
let folder_path = getFolderStructure(file.path);
|
||
|
let td2_path = td2.createEl("a", { cls: "dn-folder-path", text: folder_path, title: file.path }).onClickEvent((evt) => {
|
||
|
this._INPUT_SEARCH.value = folder_path;
|
||
|
this.dnSearchVault(this._INPUT_SEARCH.value + "$");
|
||
|
});
|
||
|
let td3 = tr2.createEl("td", { text: fSize, title: fSize + " bytes" });
|
||
|
let td4 = tr2.createEl("td", { text: fMTime, title: fMTime });
|
||
|
let tags_per_file = this.dnGetTagsPerFile(file);
|
||
|
let td5 = tr2.createEl("td", { title: tags_per_file });
|
||
|
let fTags = tags_per_file.split(" ");
|
||
|
fTags.forEach((tag) => {
|
||
|
td5.createEl("a", { cls: "dn-tag", text: tag }).onClickEvent((evt) => {
|
||
|
this._INPUT_SEARCH.value = tag;
|
||
|
this.dnSearchVault(this._INPUT_SEARCH.value);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
paginationContainer.empty();
|
||
|
const resultsCount = paginationContainer.createEl("span", { cls: "dn-pagination-total-results", text: `File(s): ${f.length}` + this._selected_category });
|
||
|
const currentPageIndicator = paginationContainer.createEl("span", { cls: "dn-pagination-current-page", text: `Page ${currentPage} of ${this._total_pages}` });
|
||
|
const btnPrev = paginationContainer.createEl("button", { cls: "dn-btn-prev", text: "\u25C0", title: "Previous" });
|
||
|
if (currentPage === 1) {
|
||
|
btnPrev.disabled = true;
|
||
|
} else {
|
||
|
btnPrev.disabled = false;
|
||
|
}
|
||
|
btnPrev.addEventListener("click", () => {
|
||
|
if (currentPage > 1) {
|
||
|
this.dnShowSearchResults({ f, el, leaf, currentPage: currentPage - 1 });
|
||
|
}
|
||
|
});
|
||
|
const btnNext = paginationContainer.createEl("button", { cls: "dn-btn-next", text: "\u25B6", title: "Next" });
|
||
|
if (currentPage === this._total_pages) {
|
||
|
btnNext.disabled = true;
|
||
|
} else {
|
||
|
btnNext.disabled = false;
|
||
|
}
|
||
|
btnNext.addEventListener("click", () => {
|
||
|
if (currentPage < this._total_pages) {
|
||
|
this.dnShowSearchResults({ f, el, leaf, currentPage: currentPage + 1 });
|
||
|
}
|
||
|
});
|
||
|
this.dnUpdateSortIndicators(
|
||
|
this._sort_column,
|
||
|
this._sort_order,
|
||
|
this._th1,
|
||
|
this._th2,
|
||
|
this._th3,
|
||
|
this._th4
|
||
|
);
|
||
|
} else {
|
||
|
tr.empty();
|
||
|
this._divSearchResults.createEl("p", { cls: "dn-no-results-found", text: "No files found." });
|
||
|
}
|
||
|
}
|
||
|
dnAlternateSortColumn(colName) {
|
||
|
switch (colName) {
|
||
|
case "name":
|
||
|
this.dnSortColumnString("name", this._sort_order, true);
|
||
|
break;
|
||
|
case "path":
|
||
|
this.dnSortColumnString("path", this._sort_order, true);
|
||
|
break;
|
||
|
case "size":
|
||
|
this.dnSortColumnNumber("size", this._sort_order, true);
|
||
|
break;
|
||
|
case "modified":
|
||
|
this.dnSortColumnNumber("modified", this._sort_order, true);
|
||
|
break;
|
||
|
}
|
||
|
this.dnShowSearchResults({ f: this._filtered_files, el: this._divSearchResults, leaf: this._leaf });
|
||
|
}
|
||
|
dnGetTagsPerFile(file) {
|
||
|
var _a, _b;
|
||
|
const cur_file = this.app.vault.getAbstractFileByPath(file.path);
|
||
|
if (cur_file !== null) {
|
||
|
const tags = (_a = this.app.metadataCache.getFileCache(file)) == null ? void 0 : _a.tags;
|
||
|
const frontmatter_tags = (_b = this.app.metadataCache.getFileCache(file)) == null ? void 0 : _b.frontmatter;
|
||
|
const arrTags = [];
|
||
|
if (tags) {
|
||
|
for (let i = 0, len = tags.length; i < len; i++) {
|
||
|
if (arrTags.indexOf(tags[i].tag) < 0) {
|
||
|
arrTags.push(tags[i].tag);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (frontmatter_tags !== void 0 && frontmatter_tags.tags) {
|
||
|
for (let i = 0, len = frontmatter_tags.tags.length; i < len; i++) {
|
||
|
if (arrTags.indexOf(frontmatter_tags.tags[i]) < 0) {
|
||
|
arrTags.push("#" + frontmatter_tags.tags[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return arrTags.join(" ");
|
||
|
} else {
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
dnUpdateSortIndicators(activeColumn, sortOrder, col1, col2, col3, col4) {
|
||
|
col1.classList.remove("sort-active", "sort-asc", "sort-desc");
|
||
|
col2.classList.remove("sort-active", "sort-asc", "sort-desc");
|
||
|
col3.classList.remove("sort-active", "sort-asc", "sort-desc");
|
||
|
col4.classList.remove("sort-active", "sort-asc", "sort-desc");
|
||
|
let activeThCell = col4;
|
||
|
switch (activeColumn) {
|
||
|
case "name":
|
||
|
activeThCell = col1;
|
||
|
break;
|
||
|
case "path":
|
||
|
activeThCell = col2;
|
||
|
break;
|
||
|
case "size":
|
||
|
activeThCell = col3;
|
||
|
break;
|
||
|
case "modified":
|
||
|
activeThCell = col4;
|
||
|
break;
|
||
|
}
|
||
|
activeThCell.classList.add("sort-active");
|
||
|
activeThCell.classList.add(sortOrder === "asc" ? "sort-asc" : "sort-desc");
|
||
|
}
|
||
|
dnSortColumnString(sortColumn, sortOrder, toggleSortOrder) {
|
||
|
const supportedColumns = ["name", "path"];
|
||
|
if (!supportedColumns.includes(sortColumn)) {
|
||
|
return;
|
||
|
}
|
||
|
if (toggleSortOrder) {
|
||
|
if (this._sort_column === sortColumn) {
|
||
|
sortOrder = sortOrder === "asc" ? "desc" : "asc";
|
||
|
} else {
|
||
|
this._sort_column = sortColumn;
|
||
|
sortOrder = "desc";
|
||
|
}
|
||
|
this._sort_order = sortOrder;
|
||
|
}
|
||
|
const sortValue = sortColumn + "-" + this._sort_order;
|
||
|
this.dnSetSelectSortValue(sortValue);
|
||
|
this._filtered_files.sort((fileA, fileB) => {
|
||
|
let sortA;
|
||
|
let sortB;
|
||
|
switch (sortColumn) {
|
||
|
case "name":
|
||
|
sortA = fileA.name.toLowerCase();
|
||
|
sortB = fileB.name.toLowerCase();
|
||
|
break;
|
||
|
case "path":
|
||
|
const folderStructureA = getFolderStructure(fileA.path);
|
||
|
const folderStructureB = getFolderStructure(fileB.path);
|
||
|
sortA = folderStructureA.toLowerCase();
|
||
|
sortB = folderStructureB.toLowerCase();
|
||
|
break;
|
||
|
default:
|
||
|
sortA = fileA.name.toLowerCase();
|
||
|
sortB = fileB.name.toLowerCase();
|
||
|
}
|
||
|
if (sortOrder === "asc") {
|
||
|
return sortA.localeCompare(sortB);
|
||
|
} else if (sortOrder === "desc") {
|
||
|
return sortB.localeCompare(sortA);
|
||
|
} else {
|
||
|
return sortA.localeCompare(sortB);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
dnSortColumnNumber(sortColumn, sortOrder, toggleSortOrder) {
|
||
|
const supportedColumns = ["size", "modified"];
|
||
|
if (!supportedColumns.includes(sortColumn)) {
|
||
|
return;
|
||
|
}
|
||
|
if (toggleSortOrder) {
|
||
|
if (this._sort_column === sortColumn) {
|
||
|
sortOrder = sortOrder === "asc" ? "desc" : "asc";
|
||
|
} else {
|
||
|
this._sort_column = sortColumn;
|
||
|
sortOrder = "desc";
|
||
|
}
|
||
|
this._sort_order = sortOrder;
|
||
|
}
|
||
|
const sortValue = sortColumn + "-" + this._sort_order;
|
||
|
this.dnSetSelectSortValue(sortValue);
|
||
|
this._filtered_files.sort((fileA, fileB) => {
|
||
|
let sortA = 0;
|
||
|
let sortB = 0;
|
||
|
switch (sortColumn) {
|
||
|
case "size":
|
||
|
sortA = fileA.stat.size;
|
||
|
sortB = fileB.stat.size;
|
||
|
break;
|
||
|
case "modified":
|
||
|
sortA = fileA.stat.mtime;
|
||
|
sortB = fileB.stat.mtime;
|
||
|
break;
|
||
|
}
|
||
|
if (sortOrder === "asc") {
|
||
|
return sortA - sortB;
|
||
|
} else if (sortOrder === "desc") {
|
||
|
return sortB - sortA;
|
||
|
} else {
|
||
|
return sortA - sortB;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
async dnGetRecentFiles(files) {
|
||
|
const arrRecentFiles = files;
|
||
|
return arrRecentFiles.sort((a, b) => b.stat.mtime - a.stat.mtime).slice(0, this.num_recent_files);
|
||
|
}
|
||
|
async dnOrganizeFiles({ arr }) {
|
||
|
const arrNotes = [];
|
||
|
const arrImages = [];
|
||
|
const arrAudios = [];
|
||
|
const arrCanvas = [];
|
||
|
const arrVideos = [];
|
||
|
const arrPDFs = [];
|
||
|
const arrOther = [];
|
||
|
const extensions = {
|
||
|
"md": arrNotes,
|
||
|
"png": arrImages,
|
||
|
"jpg": arrImages,
|
||
|
"webp": arrImages,
|
||
|
"ico": arrImages,
|
||
|
"bmp": arrImages,
|
||
|
"gif": arrImages,
|
||
|
"tif": arrImages,
|
||
|
"tiff": arrImages,
|
||
|
"raw": arrImages,
|
||
|
"mp3": arrAudios,
|
||
|
"wav": arrAudios,
|
||
|
"ogg": arrAudios,
|
||
|
"webm": arrAudios,
|
||
|
"mp4": arrVideos,
|
||
|
"avi": arrVideos,
|
||
|
"pdf": arrPDFs,
|
||
|
"canvas": arrCanvas
|
||
|
};
|
||
|
for (let i = 0, len = arr.length; i < len; i++) {
|
||
|
const f = arr[i].extension.toLowerCase();
|
||
|
const targetArr = extensions[f];
|
||
|
if (targetArr) {
|
||
|
targetArr.push(arr[i]);
|
||
|
} else {
|
||
|
arrOther.push(arr[i]);
|
||
|
}
|
||
|
}
|
||
|
this._notes = arrNotes;
|
||
|
this._images = arrImages;
|
||
|
this._audios = arrAudios;
|
||
|
this._videos = arrVideos;
|
||
|
this._pdf = arrPDFs;
|
||
|
this._canvas = arrCanvas;
|
||
|
this._other = arrOther;
|
||
|
}
|
||
|
dnSetFileIconClass(ext) {
|
||
|
const file_extension = ext.toLowerCase();
|
||
|
const extensions = {
|
||
|
"md": "note",
|
||
|
"png": "image",
|
||
|
"jpg": "image",
|
||
|
"webp": "image",
|
||
|
"ico": "image",
|
||
|
"bmp": "image",
|
||
|
"gif": "image",
|
||
|
"tif": "image",
|
||
|
"tiff": "image",
|
||
|
"raw": "image",
|
||
|
"mp3": "audio",
|
||
|
"wav": "audio",
|
||
|
"ogg": "audio",
|
||
|
"webm": "audio",
|
||
|
"mp4": "video",
|
||
|
"avi": "video",
|
||
|
"pdf": "pdf",
|
||
|
"canvas": "canvas"
|
||
|
};
|
||
|
if (file_extension in extensions) {
|
||
|
return "dn-f-" + extensions[file_extension];
|
||
|
} else {
|
||
|
return "dn-f-other";
|
||
|
}
|
||
|
}
|
||
|
dnSetView(view) {
|
||
|
const divElements = [this._VIEW_DASHBOARD, this._VIEW_NAVIGATOR];
|
||
|
const topNavBtns = [this._BTN_DASHBOARD, this._BTN_NAVIGATOR];
|
||
|
divElements.forEach((el) => {
|
||
|
el.classList.add("dn-display-none");
|
||
|
el.classList.remove("dn-flex");
|
||
|
});
|
||
|
topNavBtns.forEach((btn) => btn.classList.remove("mod-cta"));
|
||
|
switch (view) {
|
||
|
case 1:
|
||
|
this._VIEW_DASHBOARD.classList.remove("dn-display-none");
|
||
|
this._VIEW_DASHBOARD.classList.add("dn-flex");
|
||
|
this._BTN_DASHBOARD.classList.add("mod-cta");
|
||
|
this.dnHideTopRightNav();
|
||
|
break;
|
||
|
case 2:
|
||
|
this._VIEW_NAVIGATOR.classList.remove("dn-display-none");
|
||
|
this._VIEW_NAVIGATOR.classList.add("dn-flex");
|
||
|
this._BTN_NAVIGATOR.classList.add("mod-cta");
|
||
|
this.dnShowTopRightNav();
|
||
|
break;
|
||
|
default:
|
||
|
this._VIEW_DASHBOARD.classList.remove("dn-display-none");
|
||
|
this._VIEW_DASHBOARD.classList.add("dn-flex");
|
||
|
this._BTN_DASHBOARD.classList.add("mod-cta");
|
||
|
this.dnHideTopRightNav();
|
||
|
}
|
||
|
}
|
||
|
dnShowTopRightNav() {
|
||
|
this._SELECT_SORT.classList.remove("dn-display-none");
|
||
|
this._SELECT_TABLE_LAYOUT.classList.remove("dn-display-none");
|
||
|
this.labelLayout.classList.remove("dn-display-none");
|
||
|
this.labelSort.classList.remove("dn-display-none");
|
||
|
}
|
||
|
dnHideTopRightNav() {
|
||
|
this._SELECT_SORT.classList.add("dn-display-none");
|
||
|
this._SELECT_TABLE_LAYOUT.classList.add("dn-display-none");
|
||
|
this.labelLayout.classList.add("dn-display-none");
|
||
|
this.labelSort.classList.add("dn-display-none");
|
||
|
}
|
||
|
dnSetSelectSortValue(val) {
|
||
|
if (this.dnIsValidSort(val)) {
|
||
|
this.selected_sort_value = val;
|
||
|
this._SELECT_SORT.value = this.selected_sort_value;
|
||
|
}
|
||
|
}
|
||
|
dnSetSelectLayoutValue(val) {
|
||
|
if (this.dnIsValidLayout(val)) {
|
||
|
this._SELECT_TABLE_LAYOUT.value = val;
|
||
|
this.dnSelectTableLayout();
|
||
|
}
|
||
|
}
|
||
|
dnOpenFileAlt(f, evt) {
|
||
|
if (!evt || typeof evt !== "object" || !(f instanceof import_obsidian2.TFile)) {
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
if (evt.button === 0 && (evt.ctrlKey || evt.metaKey)) {
|
||
|
this.app.workspace.getLeaf("tab").openFile(f);
|
||
|
} else if (evt.button === 1) {
|
||
|
this.app.workspace.getLeaf("tab").openFile(f);
|
||
|
} else if (evt.button === 0) {
|
||
|
this.dnOpenFile(f);
|
||
|
} else if (evt.button === 2 && !(evt.target instanceof HTMLTableCellElement)) {
|
||
|
evt.preventDefault();
|
||
|
this.dnGenerateContextMenu(evt, f);
|
||
|
}
|
||
|
} catch (er) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
dnOpenFile(file) {
|
||
|
this.app.workspace.getLeaf(false).openFile(file);
|
||
|
this.close();
|
||
|
}
|
||
|
dnHandleClick(evt, file) {
|
||
|
if (!evt || typeof evt !== "object" || !(file instanceof import_obsidian2.TFile)) {
|
||
|
return;
|
||
|
}
|
||
|
this.dnSelectTableRow(evt);
|
||
|
if (evt.button === 2) {
|
||
|
evt.preventDefault();
|
||
|
this.dnGenerateContextMenu(evt, file);
|
||
|
}
|
||
|
}
|
||
|
dnHandleDblClick(evt, file) {
|
||
|
if (!evt || typeof evt !== "object" || !(file instanceof import_obsidian2.TFile)) {
|
||
|
return;
|
||
|
}
|
||
|
evt.preventDefault();
|
||
|
this.dnSelectTableRow(evt);
|
||
|
this.dnOpenFile(file);
|
||
|
}
|
||
|
dnSelectTableLayout() {
|
||
|
const val = this._SELECT_TABLE_LAYOUT.value;
|
||
|
if (this._TABLE_LAYOUTS.includes(val)) {
|
||
|
const tbl = document.getElementById("dn-table");
|
||
|
this._TABLE_LAYOUTS.forEach((layout) => tbl == null ? void 0 : tbl.classList.remove(layout));
|
||
|
tbl == null ? void 0 : tbl.classList.add(val);
|
||
|
this.selected_table_layout = val;
|
||
|
}
|
||
|
}
|
||
|
dnSelectTableRow(evt) {
|
||
|
if (!evt || typeof evt !== "object") {
|
||
|
return;
|
||
|
}
|
||
|
if (evt.target instanceof HTMLTableCellElement) {
|
||
|
const allTr = document.querySelectorAll("#dn-table tr");
|
||
|
allTr.forEach((row) => row.classList.remove("tbl-selected"));
|
||
|
const clickedTr = evt.target.parentElement;
|
||
|
clickedTr.classList.add("tbl-selected");
|
||
|
}
|
||
|
}
|
||
|
dnGenerateContextMenu(evt, file) {
|
||
|
this._DN_CTX_MENU = new import_obsidian2.Menu();
|
||
|
this._DN_CTX_MENU.addItem(
|
||
|
(item) => item.setTitle("Open").setIcon("mouse-pointer-2").onClick(() => {
|
||
|
this.app.workspace.getLeaf(false).openFile(file);
|
||
|
this.close();
|
||
|
})
|
||
|
);
|
||
|
this._DN_CTX_MENU.addSeparator();
|
||
|
this._DN_CTX_MENU.addItem(
|
||
|
(item) => item.setTitle("Open in new tab").setIcon("file-plus").onClick(() => {
|
||
|
this.app.workspace.getLeaf("tab").openFile(file);
|
||
|
this.close();
|
||
|
})
|
||
|
);
|
||
|
this._DN_CTX_MENU.addItem(
|
||
|
(item) => item.setTitle("Open to the right").setIcon("separator-vertical").onClick(() => {
|
||
|
this.app.workspace.getLeaf("split").openFile(file);
|
||
|
this.close();
|
||
|
})
|
||
|
);
|
||
|
this._DN_CTX_MENU.addItem(
|
||
|
(item) => item.setTitle("Open in new window").setIcon("picture-in-picture-2").onClick(() => {
|
||
|
this.app.workspace.getLeaf("window").openFile(file);
|
||
|
})
|
||
|
);
|
||
|
this._DN_CTX_MENU.addSeparator();
|
||
|
this._DN_CTX_MENU.addItem(
|
||
|
(item) => item.setTitle("File properties").setIcon("file-cog").onClick(() => {
|
||
|
const mdFileProps = new import_obsidian2.Modal(this.app);
|
||
|
mdFileProps.contentEl.createEl("h4", { text: "Properties" });
|
||
|
const propFileName = mdFileProps.contentEl.createEl("div");
|
||
|
propFileName.createEl("span", { text: "File name: ", cls: "dn-properties" });
|
||
|
propFileName.createEl("span", { text: file.basename });
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
const propFileExt = mdFileProps.contentEl.createEl("div");
|
||
|
propFileExt.createEl("span", { text: "Extension: ", cls: "dn-properties" });
|
||
|
propFileExt.createEl("span", { text: file.extension, cls: "nav-file-tag" });
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
const propFilePath = mdFileProps.contentEl.createEl("div");
|
||
|
propFilePath.createEl("span", { text: "Path: ", cls: "dn-properties" });
|
||
|
propFilePath.createEl("span", { text: getFolderStructure(file.path) });
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
const propFileSize = mdFileProps.contentEl.createEl("div");
|
||
|
propFileSize.createEl("span", { text: "Size: ", cls: "dn-properties" });
|
||
|
propFileSize.createEl("span", { text: formatFileSize(file.stat.size) + " bytes" });
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
const propDateCreated = mdFileProps.contentEl.createEl("div");
|
||
|
propDateCreated.createEl("span", { text: "Created: ", cls: "dn-properties" });
|
||
|
propDateCreated.createEl("span", { text: (0, import_obsidian3.moment)(file.stat.ctime).format(this.date_format) });
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
const propDateModified = mdFileProps.contentEl.createEl("div");
|
||
|
propDateModified.createEl("span", { text: "Modified: ", cls: "dn-properties" });
|
||
|
propDateModified.createEl("span", { text: (0, import_obsidian3.moment)(file.stat.mtime).format(this.date_format) });
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
const propTags = mdFileProps.contentEl.createEl("div");
|
||
|
const curTags = this.dnGetTagsPerFile(file);
|
||
|
propTags.createEl("span", { text: "Tag(s): ", cls: "dn-properties" });
|
||
|
if (curTags) {
|
||
|
const tags = curTags.split(" ");
|
||
|
for (let i = 0, len = tags.length; i < len; i++) {
|
||
|
propTags.createEl("a", { text: tags[i], cls: "dn-tag" }).onClickEvent((evt2) => {
|
||
|
mdFileProps.close();
|
||
|
this._INPUT_SEARCH.value = tags[i];
|
||
|
this.dnSearchVault(this._INPUT_SEARCH.value);
|
||
|
});
|
||
|
}
|
||
|
;
|
||
|
} else {
|
||
|
propTags.createEl("span", { text: "No tags" });
|
||
|
}
|
||
|
mdFileProps.contentEl.createEl("br");
|
||
|
mdFileProps.contentEl.createEl("hr");
|
||
|
const divBottom = mdFileProps.contentEl.createEl("div", { cls: "dn-div-bottom-properties" });
|
||
|
const btnCloseProps = divBottom.createEl("button", { text: "Ok", cls: "dn-btn-close-properties" });
|
||
|
btnCloseProps.onClickEvent(() => {
|
||
|
mdFileProps.close();
|
||
|
});
|
||
|
mdFileProps.open();
|
||
|
})
|
||
|
);
|
||
|
this._DN_CTX_MENU.showAtMouseEvent(evt);
|
||
|
}
|
||
|
onClose() {
|
||
|
const { contentEl } = this;
|
||
|
contentEl.empty();
|
||
|
if (this._INPUT_SEARCH && this._INPUT_SEARCH.removeEventListener) {
|
||
|
this._INPUT_SEARCH.removeEventListener("input", (0, import_obsidian2.debounce)(() => this.dnSearchVault(this._INPUT_SEARCH.value), 300, true));
|
||
|
}
|
||
|
this._th1.removeEventListener("dblclick", () => this.dnAlternateSortColumn("name"));
|
||
|
this._th2.removeEventListener("dblclick", () => this.dnAlternateSortColumn("path"));
|
||
|
this._th3.removeEventListener("dblclick", () => this.dnAlternateSortColumn("size"));
|
||
|
this._th4.removeEventListener("dblclick", () => this.dnAlternateSortColumn("modified"));
|
||
|
this._SELECT_SORT.removeEventListener("change", () => {
|
||
|
this.dnSortColumnWithSelect();
|
||
|
});
|
||
|
if (this.intersectionObserver) {
|
||
|
this.intersectionObserver.disconnect();
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// src/main.ts
|
||
|
var DEFAULT_SETTINGS = {
|
||
|
default_view: 1,
|
||
|
font_size: 16,
|
||
|
selected_table_layout: "dn-tbl-default",
|
||
|
date_format: "YYYY-MM-DD HH:mm",
|
||
|
files_per_page: 20,
|
||
|
num_recent_files: 5,
|
||
|
excluded_ext: "",
|
||
|
excluded_path: "",
|
||
|
color_notes: "#bf48ff",
|
||
|
color_images: "#007fff",
|
||
|
color_canvas: "#ff7f28",
|
||
|
color_videos: "#d34848",
|
||
|
color_audios: "#bfbf00",
|
||
|
color_pdf: "#00a300",
|
||
|
color_other: "#828282",
|
||
|
colored_files: false
|
||
|
};
|
||
|
var DNPlugin = class extends import_obsidian4.Plugin {
|
||
|
async onload() {
|
||
|
await this.loadSettings();
|
||
|
this._DN_MODAL = new DNModal(this.app);
|
||
|
this._DN_MODAL.default_view = this.settings.default_view;
|
||
|
this._DN_MODAL.date_format = this.settings.date_format;
|
||
|
this._DN_MODAL.num_recent_files = this.settings.num_recent_files;
|
||
|
this._DN_MODAL.files_per_page = this.settings.files_per_page;
|
||
|
this._DN_MODAL.selected_table_layout = this.settings.selected_table_layout;
|
||
|
this._DN_MODAL.excluded_extensions = this.dnGetExcludedExtensions(this.settings.excluded_ext);
|
||
|
this._DN_MODAL.excluded_folders = this.dnGetExcludedFolders(this.settings.excluded_path);
|
||
|
this.dnSetFontSize(this.settings.font_size);
|
||
|
this._DN_MODAL.colored_files = this.settings.colored_files;
|
||
|
this._DN_MODAL.color_notes = this.settings.color_notes;
|
||
|
this._DN_MODAL.color_canvas = this.settings.color_canvas;
|
||
|
this._DN_MODAL.color_images = this.settings.color_images;
|
||
|
this._DN_MODAL.color_videos = this.settings.color_videos;
|
||
|
this._DN_MODAL.color_audios = this.settings.color_audios;
|
||
|
this._DN_MODAL.color_pdf = this.settings.color_pdf;
|
||
|
this._DN_MODAL.color_other = this.settings.color_other;
|
||
|
this.addRibbonIcon("gauge", "Open dashboard navigator", (evt) => {
|
||
|
this._DN_MODAL.default_view = this.settings.default_view;
|
||
|
this._DN_MODAL.open();
|
||
|
});
|
||
|
this.addCommand({
|
||
|
id: "activate",
|
||
|
name: "Open",
|
||
|
callback: () => {
|
||
|
this._DN_MODAL.default_view = this.settings.default_view;
|
||
|
this._DN_MODAL.open();
|
||
|
}
|
||
|
});
|
||
|
this.addCommand({
|
||
|
id: "dashboard",
|
||
|
name: "Open dashboard",
|
||
|
callback: () => {
|
||
|
this._DN_MODAL.default_view = 1;
|
||
|
this._DN_MODAL.open();
|
||
|
}
|
||
|
});
|
||
|
this.addCommand({
|
||
|
id: "navigator",
|
||
|
name: "Open navigator",
|
||
|
callback: () => {
|
||
|
this._DN_MODAL.default_view = 2;
|
||
|
this._DN_MODAL.open();
|
||
|
}
|
||
|
});
|
||
|
this.addSettingTab(new DNSettingTab(this.app, this));
|
||
|
}
|
||
|
dnGetExcludedFolders(foldersString) {
|
||
|
if (foldersString === "") {
|
||
|
return [];
|
||
|
}
|
||
|
const folders = foldersString.split(",").map((folder) => folder.trim());
|
||
|
return folders.map((folder) => folder.replace(/^\/|\/$|\.\./g, "")).filter((folder) => folder !== "");
|
||
|
}
|
||
|
dnSetFontSize(val) {
|
||
|
if (val >= 12 || val <= 24) {
|
||
|
const styles = getComputedStyle(document.body);
|
||
|
const fontSize = styles.getPropertyValue("--dn-font-size");
|
||
|
document.body.style.setProperty("--dn-font-size", val.toString() + "px");
|
||
|
}
|
||
|
}
|
||
|
dnGetExcludedExtensions(excluded_ext) {
|
||
|
if (excluded_ext === "") {
|
||
|
return [];
|
||
|
}
|
||
|
return excluded_ext.split(",").map((extension) => extension.trim());
|
||
|
}
|
||
|
onunload() {
|
||
|
}
|
||
|
async loadSettings() {
|
||
|
this.settings = Object.assign(
|
||
|
{},
|
||
|
DEFAULT_SETTINGS,
|
||
|
await this.loadData()
|
||
|
);
|
||
|
}
|
||
|
async saveSettings() {
|
||
|
await this.saveData(this.settings);
|
||
|
}
|
||
|
};
|
||
|
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsic3JjL21haW4udHMiLCAic3JjL3NldHRpbmdzLnRzIiwgInNyYy9kbi50cyIsICJzcmMvdXRpbHMvZm9ybWF0LnRzIiwgInNyYy91dGlscy9waWVjaGFydC50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0IHsgUGx1Z2luIH0gZnJvbSAnb2JzaWRpYW4nO1xuaW1wb3J0IHsgRE5TZXR0aW5nVGFiIH0gZnJvbSAnLi9zZXR0aW5ncyc7XG5pbXBvcnQgeyBETk1vZGFsIH0gZnJvbSAnLi9kbic7XG5cbmludGVyZmFjZSBETlNldHRpbmdzIHtcblx0ZGVmYXVsdF92aWV3OiBudW1iZXI7XG5cdGZvbnRfc2l6ZTogbnVtYmVyO1xuXHRzZWxlY3RlZF90YWJsZV9sYXlvdXQ6IHN0cmluZztcblx0ZGF0ZV9mb3JtYXQ6IHN0cmluZztcblx0ZmlsZXNfcGVyX3BhZ2U6IG51bWJlcjtcblx0bnVtX3JlY2VudF9maWxlczogbnVtYmVyO1xuXHRleGNsdWRlZF9leHQ6IHN0cmluZztcblx0ZXhjbHVkZWRfcGF0aDogc3RyaW5nO1xuXHRjb2xvcl9ub3Rlczogc3RyaW5nO1xuXHRjb2xvcl9jYW52YXM6IHN0cmluZztcblx0Y29sb3JfaW1hZ2VzOiBzdHJpbmc7XG5cdGNvbG9yX3ZpZGVvczogc3RyaW5nO1xuXHRjb2xvcl9hdWRpb3M6IHN0cmluZztcblx0Y29sb3JfcGRmOiBzdHJpbmc7XG5cdGNvbG9yX290aGVyOiBzdHJpbmc7XG5cdGNvbG9yZWRfZmlsZXM6IGJvb2xlYW47XG59XG5cbmV4cG9ydCBjb25zdCBERUZBVUxUX1NFVFRJTkdTOiBETlNldHRpbmdzID0ge1xuXHRkZWZhdWx0X3ZpZXc6IDEsXG5cdGZvbnRfc2l6ZTogMTYsXG5cdHNlbGVjdGVkX3RhYmxlX2xheW91dDogJ2RuLXRibC1kZWZhdWx0Jyxcblx0ZGF0ZV9mb3JtYXQ6ICdZWVlZLU1NLUREIEhIOm1tJyxcblx0ZmlsZXNfcGVyX3BhZ2U6IDIwLFxuXHRudW1fcmVjZW50X2ZpbGVzOiA1LFxuXHRleGNsdWRlZF9leHQ6ICcnLFxuXHRleGNsdWRlZF9wYXRoOiAnJyxcblx0Y29sb3Jfbm90ZXM6ICcjYmY0OGZmJyxcblx0Y29sb3JfaW1hZ2VzOiAnIzAwN2ZmZicsXG5cdGNvbG9yX2NhbnZhczogJyNmZjdmMjgnLFxuXHRjb2xvcl92aWRlb3M6ICcjZDM0ODQ4Jyxcblx0Y29sb3JfYXVkaW9zOiAnI2JmYmYwMCcsXG5cdGNvbG9yX3BkZjogJyMwMGEzMDAnLFxuXHRjb2xvcl9vdGhlcjogJyM4MjgyODInLFxuXHRjb2xvcmVkX2ZpbGVzOiBmYWxzZVxufVxuXG5leHBvcnQgZGVmYXVsdCBjbGFzcyBETlBsdWdpbiBleHRlbmRzIFBsdWdpbiB7XG5cblx0X0ROX01PREFMOiBETk1vZGFsO1xuXG5cdHNldHRpbmdzOiBETlNldHRpbmdzO1xuXG5cdGFzeW5jIG9ubG9hZCgpIHtcblxuXHRcdGF3YWl0IHRoaXMubG9hZFNldHRpbmdzKCk7XG5cblx0XHR0aGlzLl9ETl9NT0RBTCA9IG5ldyBETk1vZGFsKHRoaXMuYXBwKTtcblxuXHRcdC8vIFNldCBtb2RhbCBzZXR0aW5nc1xuXHRcdHRoaXMuX0ROX01PREFMLmRlZmF1bHRfdmlldyA9IHRoaXMuc2V0dGluZ3MuZGVmYXVsdF92aWV3O1xuXHRcdHRoaXMuX0ROX01PREFMLmRhdGVfZm9ybWF0ID0gdGhpcy5zZXR0aW5ncy5kYXRlX2Zvcm1hdDtcblx0XHR0aGlzLl9ETl9NT0RBTC5udW1fcmVjZW50X2ZpbGVzID0gdGhpcy5zZXR0aW5ncy5udW1fcmVjZW50X2ZpbGVzO1xuXHRcdHRoaXMuX0ROX01PREFMLmZpbGVzX3Blcl9wYWdlID0gdGhpcy5zZXR0aW5ncy5maWxlc19wZXJfcGFnZTtcblx0XHR0aGlzLl9ETl9NT0RBTC5zZWxlY3RlZF90YWJsZV9sYXlvdXQgPSB0aGlzLnNldHRpbmdzLnNlbGVjdGVkX3RhYmxlX2xheW91dDtcblx0XHR0aGlzLl9ETl9NT0RBTC5leGNsdWRlZF9leHRlbnNpb25zID0gdGhpcy5kbkdldEV4Y2x1ZGVkRXh0ZW5zaW9ucyh0aGlzLnNldHRpbmdzLmV4Y2x1ZGVkX2V4dCk7XG5cdFx0dGhpcy5fRE5fTU9EQUwuZXhjbHVkZWRfZm9sZGVycyA9IHRoaXMuZG5HZXRFeGNsdWRlZEZvbGRlcnModGhpcy5zZXR0aW5ncy5leGNsdWRlZF9wYXRoKTtcblx0XHR0aGlzLmRuU2V0Rm9udFNpemUodGhpcy5zZXR0aW5ncy5mb250X3NpemUpO1xuXHRcdC8vIFNldCBjb2xvcnNcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcmVkX2ZpbGVzID0gdGhpcy5zZXR0aW5ncy5jb2xvcmVkX2ZpbGVzO1xuXHRcdHRoaXMuX0ROX01PREFMLmNvbG9yX25vdGVzID0gdGhpcy5zZXR0aW5ncy5jb2xvcl9ub3Rlcztcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcl9jYW52YXMgPSB0aGlzLnNldHRpbmdzLmNvbG9yX2NhbnZhcztcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcl9pbWFnZXMgPSB0aGlzLnNldHRpbmdzLmNvbG9yX2ltYWdlcztcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcl92aWRlb3MgPSB0aGlzLnNldHRpbmdzLmNvbG9yX3ZpZGVvcztcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcl9hdWRpb3MgPSB0aGlzLnNldHRpbmdzLmNvbG9yX2F1ZGlvcztcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcl9wZGYgPSB0aGlzLnNldHRpbmdzLmNvbG9yX3BkZjtcblx0XHR0aGlzLl9ETl9NT0RBTC5jb2xvcl9vdGhlciA9IHRoaXMuc2V0dGluZ3MuY29sb3Jfb3RoZXI7XG5cblx0XHR0aGlzLmFkZFJpYmJvbkljb24oJ2dhdWdlJywgJ09wZW4gZGFzaGJvYXJkIG5hdmlnYXRvcicsIChldnQ6IE1vdXNlRXZlbnQpID0+IHtcblx0XHRcdHRoaXMuX0ROX01PREFMLmRlZmF1bHRfdmlldyA9IHRoaXMuc2V0dGluZ3MuZGVmYXVsdF92aWV3O1xuXHRcdFx0dGhpcy5fRE5fTU9EQUwub3BlbigpO1xuXHRcdH0pO1xuXG5cblx0XHR0aGlzLmFkZENvbW1hbmQoe1xuXHRcdFx0aWQ6ICdhY3RpdmF0ZScsXG5cdFx0XHRuYW1lOiAnT3BlbicsXG5cdFx0XHRjYWxsYmFjazogKCkgPT4ge1xuXHRcdFx0XHR0aGlzLl9ETl9NT0RBTC5kZWZhdWx0X3ZpZXcgPSB0aGlzLnNldHRpbmdzLmRlZmF1bHRfdmlldztcblx0XHRcdFx0dGhpcy5fRE5fTU9EQUwub3BlbigpO1xuXHRcdFx0fVxuXHRcdH0pO1xuXG5cdFx0dGhpcy5hZGRDb21tYW5kKHtcblx0XHRcdGlkOiAnZGFzaGJvYXJkJyxcblx0XHRcdG5hbWU6ICdPcGVuIGRhc2hib2FyZCcsXG5cdFx0XHRjYWxsYmFjazogKCkgPT4ge1xuXHRcdFx0XHR0aGlzL
|