mirror of
https://github.com/decaf-dev/obsidian-vault-explorer.git
synced 2026-07-22 10:10:31 +00:00
Update default values (#327)
* feat: add default value to properties * feat: rename to File system * refactor: update value * chore: update guardgen
This commit is contained in:
parent
b63126791b
commit
19ef005f84
7 changed files with 50 additions and 52 deletions
|
|
@ -7,10 +7,9 @@ export const HOVER_LINK_SOURCE_ID = "vault-explorer-preview";
|
|||
|
||||
export const DEFAULT_SETTINGS: VaultExplorerPluginSettings = {
|
||||
properties: {
|
||||
favorite: "",
|
||||
url: "",
|
||||
image: "",
|
||||
coverImageFit: "",
|
||||
url: "url",
|
||||
image: "image",
|
||||
coverImageFit: "image-fit",
|
||||
createdDate: "",
|
||||
modifiedDate: "",
|
||||
custom1: "",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { App } from "obsidian"
|
||||
import { App } from "obsidian";
|
||||
import { ObsidianProperty, ObsidianPropertyType } from "./types";
|
||||
|
||||
/**
|
||||
|
|
@ -6,17 +6,34 @@ import { ObsidianProperty, ObsidianPropertyType } from "./types";
|
|||
* NOTE: This is an undocumented API function and may break in future versions of Obsidian
|
||||
*/
|
||||
export const getAllObsidianProperties = (app: App) => {
|
||||
const properties = (app as any).metadataTypeManager.getAllProperties() as Record<string, ObsidianProperty>;
|
||||
return Object.values(properties).sort((a: ObsidianProperty, b: ObsidianProperty) => a.name.localeCompare(b.name));
|
||||
const properties = (
|
||||
app as any
|
||||
).metadataTypeManager.getAllProperties() as Record<
|
||||
string,
|
||||
ObsidianProperty
|
||||
>;
|
||||
return Object.values(properties).sort(
|
||||
(a: ObsidianProperty, b: ObsidianProperty) =>
|
||||
a.name.localeCompare(b.name)
|
||||
);
|
||||
};
|
||||
|
||||
export const getObsidianPropertiesByType = (app: App, type: ObsidianPropertyType) => {
|
||||
export const getObsidianPropertiesByType = (
|
||||
app: App,
|
||||
type: ObsidianPropertyType
|
||||
) => {
|
||||
return getAllObsidianProperties(app).filter((p) => p.type === type);
|
||||
}
|
||||
};
|
||||
|
||||
export const getDropdownOptionsForProperties = (properties: ObsidianProperty[]) => {
|
||||
return properties.reduce((acc: Record<string, string>, cur: ObsidianProperty) => {
|
||||
acc[cur.name] = cur.name;
|
||||
return acc;
|
||||
}, { "": "Select a property" });
|
||||
}
|
||||
export const getDropdownOptionsForProperties = (
|
||||
properties: ObsidianProperty[],
|
||||
defaultValue: Record<string, string> = { "": "Select a property" }
|
||||
) => {
|
||||
return properties.reduce(
|
||||
(acc: Record<string, string>, cur: ObsidianProperty) => {
|
||||
acc[cur.name] = cur.name;
|
||||
return acc;
|
||||
},
|
||||
defaultValue
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -446,26 +446,6 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
|
||||
new Setting(containerEl).setName("Built-in properties").setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Favorite property")
|
||||
.setDesc(
|
||||
"Property used to mark a note as a favorite. This must be a checkbox property."
|
||||
)
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(
|
||||
getDropdownOptionsForProperties(checkboxProperties)
|
||||
)
|
||||
.setValue(this.plugin.settings.properties.favorite)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.properties.favorite = value;
|
||||
await this.plugin.saveSettings();
|
||||
EventManager.getInstance().emit(
|
||||
PluginEvent.PROPERTY_SETTING_CHANGE
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Cover image property")
|
||||
.setDesc(
|
||||
|
|
@ -473,7 +453,11 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
)
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(getDropdownOptionsForProperties(textProperties))
|
||||
.addOptions(
|
||||
getDropdownOptionsForProperties(textProperties, {
|
||||
image: "image",
|
||||
})
|
||||
)
|
||||
.setValue(this.plugin.settings.properties.image)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.properties.image = value;
|
||||
|
|
@ -491,7 +475,11 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
)
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(getDropdownOptionsForProperties(textProperties))
|
||||
.addOptions(
|
||||
getDropdownOptionsForProperties(textProperties, {
|
||||
"image-fit": "image-fit",
|
||||
})
|
||||
)
|
||||
.setValue(this.plugin.settings.properties.coverImageFit)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.properties.coverImageFit = value;
|
||||
|
|
@ -509,7 +497,11 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
)
|
||||
.addDropdown((dropdown) =>
|
||||
dropdown
|
||||
.addOptions(getDropdownOptionsForProperties(textProperties))
|
||||
.addOptions(
|
||||
getDropdownOptionsForProperties(textProperties, {
|
||||
url: "url",
|
||||
})
|
||||
)
|
||||
.setValue(this.plugin.settings.properties.url)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.properties.url = value;
|
||||
|
|
@ -525,7 +517,7 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
text: "Property used to store a creation date. This must be a date or datetime property.",
|
||||
});
|
||||
creationDateDesc.createDiv({
|
||||
text: "If set to 'Select a property', the file's created at date will be used.",
|
||||
text: "If set, the property will be preferred over the file's creation date.",
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -554,7 +546,7 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
|
|||
text: "Property used to store a modification date. This must be a date or datetime property.",
|
||||
});
|
||||
modificationDateDesc.createDiv({
|
||||
text: "If set to 'Select a property', the file's modified at date will be used.",
|
||||
text: "If set, the property will be preferred over the file's modification date.",
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
|
|||
|
|
@ -754,14 +754,6 @@
|
|||
const { properties } = plugin.settings;
|
||||
const { coverImageFit: coverImageFitProperty } = properties;
|
||||
|
||||
//If the favorite property is not set, return
|
||||
if (coverImageFitProperty === "") {
|
||||
new Notice(
|
||||
"Vault Explorer: Please set a cover image fit property in the plugin settings to use this feature",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const file = plugin.app.vault.getFileByPath(filePath);
|
||||
if (!file) {
|
||||
Logger.error({
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ export function isVaultExplorerPluginSettings(obj: unknown): obj is VaultExplore
|
|||
(typedObj["properties"] !== null &&
|
||||
typeof typedObj["properties"] === "object" ||
|
||||
typeof typedObj["properties"] === "function") &&
|
||||
typeof typedObj["properties"]["favorite"] === "string" &&
|
||||
typeof typedObj["properties"]["url"] === "string" &&
|
||||
typeof typedObj["properties"]["image"] === "string" &&
|
||||
typeof typedObj["properties"]["coverImageFit"] === "string" &&
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
/** @see {isVaultExplorerPluginSettings} ts-auto-guard:type-guard */
|
||||
export interface VaultExplorerPluginSettings {
|
||||
properties: {
|
||||
favorite: string;
|
||||
url: string;
|
||||
image: string;
|
||||
coverImageFit: string;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
"modifiedDate": "modification",
|
||||
"createdDate": "creation",
|
||||
"image": "image",
|
||||
"coverImageFit": ""
|
||||
"coverImageFit": "image-fit"
|
||||
},
|
||||
"filters": {
|
||||
"search": {
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
},
|
||||
"sort": {
|
||||
"isEnabled": true,
|
||||
"value": "file-name-asc"
|
||||
"value": "modified-desc"
|
||||
},
|
||||
"custom": {
|
||||
"isEnabled": true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue