diff --git a/src/components/ui/modals/stickerModal.tsx b/src/components/ui/modals/stickerModal.tsx index a127198..d96cadc 100644 --- a/src/components/ui/modals/stickerModal.tsx +++ b/src/components/ui/modals/stickerModal.tsx @@ -48,14 +48,17 @@ export class stickerModal extends FuzzySuggestModal { } getItems(): Sticker[] { - const allLucide: Sticker[] = lucideIcons.map((f) => ({ + let stickers: Sticker[] = []; + + if (this.plugin.settings.stickerIcon) stickers = stickers.concat(lucideIcons.map((f) => ({ name: f, type: "lucide", keywords: f, value: f, html: getIcon(f).outerHTML, - })); - const allCustom: Sticker[] = [...this.plugin.index.iconsCache.keys()].map( + }))); + + if (this.plugin.settings.stickerSVG) stickers = stickers.concat([...this.plugin.index.iconsCache.keys()].map( (f) => ({ name: f, type: "vault", @@ -63,8 +66,9 @@ export class stickerModal extends FuzzySuggestModal { value: f, html: this.plugin.index.iconsCache.get(f), }) - ); - const allEmojis: Sticker[] = Object.keys(emojis as EmojiData).reduce( + )); + + if (this.plugin.settings.stickerEmoji) stickers = stickers.concat(Object.keys(emojis as EmojiData).reduce( (p, c: string) => [ ...p, ...emojis[c].map((e) => ({ @@ -75,8 +79,11 @@ export class stickerModal extends FuzzySuggestModal { })), ], [] - ); - return [...allCustom, ...allEmojis, ...allLucide]; + )); + + console.log(stickers); + + return stickers; } onChooseItem(item: Sticker, evt: MouseEvent | KeyboardEvent) { diff --git a/src/i18n.ts b/src/i18n.ts index 9e9151e..07df82d 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -404,11 +404,11 @@ class T { }, spacesStickers: { name: "Stickers", - desc: `Use Emojis to make it easier to find your notes`, + desc: `Add stickers to your files to make them easier to find.`, }, spacesAlias: { name: "Alias", - desc: `Use the alias metadata to show in Spaces`, + desc: `Use the file's alias (if specified) instead of the file name in Spaces.`, }, spacesFileExplorerDual: { name: "Compatibility Mode", @@ -435,7 +435,16 @@ class T { name: "Performance Mode", desc: `Turn on performance mode for Spaces, may affect scrolling appearance. Requires Restart`, }, - indexSVG: { + + stickerEmoji: { + name: "Use Emojis as Stickers", + desc: `Use vanilla emojis as stickers`, + }, + stickerIcon: { + name: "Use Lucide Icons as Stickers", + desc: `Use line art Lucide icons as stickers (https://lucide.dev)`, + }, + stickerSvg: { name: "Use SVGs as Stickers", desc: `Use any svg file in your vault as a sticker`, }, diff --git a/src/settings/settings.ts b/src/settings/settings.ts index efaeaa2..cd02f34 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -74,7 +74,9 @@ export const DEFAULT_SETTINGS: MakeMDPluginSettings = { fmKeyColor: 'color', fmKeySticker: 'sticker', openSpacesOnLaunch: true, - indexSVG: false + stickerSVG: false, + stickerEmoji: true, + stickerIcon: true, }; export class MakeMDPluginSettingsTab extends PluginSettingTab { @@ -111,7 +113,7 @@ export class MakeMDPluginSettingsTab extends PluginSettingTab { this.refreshView(); }) ); - + if (this.plugin.settings.spacesEnabled) { containerEl.createEl("h3", { text: t.settings.sectionAppearance }); const spaceAppearances = containerEl.createEl("div"); @@ -149,7 +151,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.saveSettings(); }) ); - + new Setting(spaceAppearances) .setName(t.settings.folderIndentationLines.name) .setDesc(t.settings.folderIndentationLines.desc) @@ -163,18 +165,6 @@ if (this.plugin.settings.spacesEnabled) { }) ); new Setting(spaceAppearances) - .setName(t.settings.spacesStickers.name) - .setDesc(t.settings.spacesStickers.desc) - .addToggle((toggle) => - toggle - .setValue(this.plugin.settings.spacesStickers) - .onChange((value) => { - this.plugin.settings.spacesStickers = value; - this.plugin.saveSettings(); - this.refreshView(); - }) - ); - new Setting(spaceAppearances) .setName(t.settings.spacesAlias.name) .setDesc(t.settings.spacesAlias.desc) .addToggle((toggle) => @@ -209,7 +199,60 @@ if (this.plugin.settings.spacesEnabled) { await this.plugin.saveSettings(); }); }); + + + containerEl.createEl("h3", { text: "Stickers" }); + + new Setting(containerEl) + .setName(t.settings.spacesStickers.name) + .setDesc(t.settings.spacesStickers.desc) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.spacesStickers) + .onChange((value) => { + this.plugin.settings.spacesStickers = value; + this.plugin.saveSettings(); + this.refreshView(); + }) + ); + new Setting(containerEl) + .setName(t.settings.stickerSvg.name) + .setDesc(t.settings.stickerSvg.desc) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.stickerSVG) + .onChange((value) => { + this.plugin.settings.stickerSVG = value; + this.plugin.saveSettings(); + }) + ); + + new Setting(containerEl) + .setName(t.settings.stickerEmoji.name) + .setDesc(t.settings.stickerEmoji.desc) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.stickerEmoji) + .onChange((value) => { + this.plugin.settings.stickerEmoji = value; + this.plugin.saveSettings(); + }) + ); + + new Setting(containerEl) + .setName(t.settings.stickerIcon.name) + .setDesc(t.settings.stickerIcon.desc) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.stickerIcon) + .onChange((value) => { + this.plugin.settings.stickerIcon = value; + this.plugin.saveSettings(); + }) + ); + containerEl.createEl("h3", { text: "Folder Note" }); + new Setting(containerEl) .setName(t.settings.folderNote.name) .setDesc(t.settings.folderNote.desc) @@ -258,7 +301,7 @@ if (this.plugin.settings.spacesEnabled) { await this.plugin.saveSettings(); }); }); - + new Setting(containerEl) .setName(t.settings.spaceAutoBackup.name) .setDesc(t.settings.spaceAutoBackup.desc) @@ -270,7 +313,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.saveSettings(); }) ); - + new Setting(containerEl) .setName(t.settings.spaceAutoBackupInterval.name) .setDesc(t.settings.spaceAutoBackupInterval.desc) @@ -308,7 +351,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.saveSettings(); }) ); - + new Setting(containerEl) .setName(t.settings.spacesFileExplorerDual.name) .setDesc(t.settings.spacesFileExplorerDual.desc) @@ -320,7 +363,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.saveSettings(); }) ); - + new Setting(containerEl) .setName(t.settings.spacesPerformance.name) .setDesc(t.settings.spacesPerformance.desc) @@ -333,18 +376,6 @@ if (this.plugin.settings.spacesEnabled) { }) ); - new Setting(containerEl) - .setName(t.settings.indexSVG.name) - .setDesc(t.settings.indexSVG.desc) - .addToggle((toggle) => - toggle - .setValue(this.plugin.settings.indexSVG) - .onChange((value) => { - this.plugin.settings.indexSVG = value; - this.plugin.saveSettings(); - }) - ); - new Setting(containerEl) .setName(t.settings.spacesDeleteOption.name) .setDesc(t.settings.spacesDeleteOption.desc) @@ -365,7 +396,7 @@ if (this.plugin.settings.spacesEnabled) { }); }); } - + containerEl.createEl("h1", { text: "Context" }); new Setting(containerEl) .setName(t.settings.contexts.name) @@ -391,9 +422,9 @@ if (this.plugin.settings.spacesEnabled) { await this.plugin.saveSettings(); }); }); - - - + + + containerEl.createEl("h3", { text: t.settings.sectionAdvanced }); new Setting(containerEl) .setName(t.settings.openFileContext.name) @@ -406,7 +437,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.saveSettings(); }) ); - + new Setting(containerEl) .setName(t.settings.syncContextToFrontmatter.name) .setDesc(t.settings.syncContextToFrontmatter.desc) @@ -431,7 +462,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.reloadExtensions(false); }) ); - + containerEl.createEl("h1", { text: t.settings.sectionFlow }); new Setting(containerEl) .setName(t.settings.editorMakerMode.name) @@ -445,8 +476,8 @@ if (this.plugin.settings.spacesEnabled) { ); if (this.plugin.settings.makerMode) { - - containerEl.createEl("h3", { text: "Inline Context" }); + + containerEl.createEl("h3", { text: "Inline Context" }); new Setting(containerEl) .setName(t.settings.inlineContextExplorer.name) .setDesc(t.settings.inlineContextExplorer.desc) @@ -530,7 +561,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.reloadExtensions(false); }) ); - containerEl.createEl("h3", { text: "Flow Block" }); + containerEl.createEl("h3", { text: "Flow Block" }); new Setting(containerEl) .setName(t.settings.editorFlowReplace.name) .setDesc(t.settings.editorFlowReplace.desc) @@ -553,7 +584,7 @@ if (this.plugin.settings.spacesEnabled) { this.plugin.reloadExtensions(false); }) ); - + new Setting(containerEl) .setName(t.settings.editorFlowStyle.name) .setDesc(t.settings.editorFlowStyle.desc) @@ -577,10 +608,10 @@ if (this.plugin.settings.spacesEnabled) { }); }); - - + + containerEl.createEl("h3", { text: "Flow Menu" }); new Setting(containerEl) .setName(t.settings.editorMakeMenu.name) @@ -619,7 +650,7 @@ if (this.plugin.settings.spacesEnabled) { await this.plugin.saveSettings(); }); }); - + new Setting(containerEl) .setName(t.settings.editorMakePlacholder.name) .setDesc(t.settings.editorMakePlacholder.desc) @@ -633,7 +664,7 @@ if (this.plugin.settings.spacesEnabled) { }) ); containerEl.createEl("h3", { text: "Flow Styler" }); - + new Setting(containerEl) .setName(t.settings.inlineStyler.name) @@ -698,7 +729,7 @@ if (this.plugin.settings.spacesEnabled) { // }); // }); - + // new Setting(containerEl) // .setName(t.settings.editorMarkSans.name) // .setDesc(t.settings.editorMarkSans.desc) diff --git a/src/superstate/superstate.ts b/src/superstate/superstate.ts index 32b892a..e7bbe04 100644 --- a/src/superstate/superstate.ts +++ b/src/superstate/superstate.ts @@ -95,12 +95,12 @@ export class Superstate extends Component { //Obsidian Cache public vault: Vault; public metadataCache: MetadataCache; - + //Index public filesIndex: Map public contextsIndex: Map public spacesIndex: Map - + //Persistant Cache public vaultDBCache: DBRows public spacesDBCache: DBRows @@ -108,18 +108,18 @@ export class Superstate extends Component { public persister: LocalStorageCache; public syncStatus: number; public spacesDBLoaded: boolean; - + //Maps public spacesMap: IndexMap //file to space mapping public linksMap: IndexMap //link between files public iconsCache: Map public tagsMap: IndexMap //file to tag mapping public contextsMap: IndexMap //file to context mapping - + //Workers private contextStoreQueue: Promise; public indexer: Manager; - + private constructor(public app: App, public indexVersion: string, public onChange: () => void, plugin: MakeMDPlugin) { super(); @@ -157,13 +157,13 @@ export class Superstate extends Component { this.loadSpacesDatabaseFromDisk(); } - + private addToContextStoreQueue(operation: () => Promise) { //Simple queue (FIFO) for processing context changes this.contextStoreQueue = this.contextStoreQueue.then(operation).catch(() => {}); } - + public async resolveSpacesDatabaseSync () { //Wait and Resolve Conflicts in Spaces Database Update Time if (this.plugin.settings.spacesSyncLastUpdated.length > 0) { @@ -177,7 +177,7 @@ export class Superstate extends Component { } return true; } - + const resolverFile = getAbstractFileAtPath(app, this.plugin.settings.spacesSyncLastUpdated); if (!resolverFile) { await this.updateSpaceLastUpdated(); @@ -209,12 +209,12 @@ export class Superstate extends Component { } } - + public async loadSpacesDatabaseFromDisk () { //Load Spaces Database File if (this.plugin.settings.spacesEnabled) { await this.resolveSpacesDatabaseSync(); - + const db = await getDB(await this.plugin.sqlJS(), this.plugin.spacesDBPath); const tables = dbResultsToDBTables( db.exec( @@ -234,7 +234,7 @@ export class Superstate extends Component { this.spacesDBCache = selectDB(db, "spaces")?.rows ?? [] db.close(); this.spacesDBLoaded = true; - + this.spacesDBCache.forEach(f => this.reloadSpace(f.name, false)) if (!this.plugin.settings.precreateVaultSpace || this.spacesDBCache.length == 0) { insertSpaceAtIndex( @@ -251,9 +251,9 @@ export class Superstate extends Component { } } rebuildIndex(this.plugin, true); - + } - + public async updateSpaceLastUpdated () { if (this.plugin.settings.spacesSyncLastUpdated.length > 0) { return app.vault.adapter.stat(this.plugin.spacesDBPath).then((f) => { @@ -280,7 +280,7 @@ export class Superstate extends Component { if (save && this.plugin.settings.spacesEnabled && this.syncStatus == 0) { this.debounceSaveSpaceDatabase(tables); } - + } private debounceSaveSpaceDatabase = debounce( (tables: DBTables) => { @@ -289,14 +289,14 @@ export class Superstate extends Component { { leading: false, }) - + public async initialize () { const start = Date.now(); if (this.plugin.settings.spacesEnabled) await this.initializeSpaces(); await this.initializeContexts(); - + await this.initalizeFiles(); this.cleanContexts(); console.log(`Make.md Superstate: ${Date.now()-start} ms`); @@ -327,9 +327,9 @@ export class Superstate extends Component { } public async loadFromCache() { - + const allFiles = getAllAbstractFilesInVault(this.plugin, app) - if (this.plugin.settings.indexSVG) { + if (this.plugin.settings.stickerSVG) { const cacheIcons = allFiles.filter(f => (f instanceof TFile) && f.extension == 'svg').map(s => this.persister.load(s.path, 'icon').then(string => { if (string?.length > 0) this.iconsCache.set(s.path, string); @@ -338,7 +338,7 @@ export class Superstate extends Component { } const cachePromises = allFiles.map(file => this.persister.load(file.path, 'file').then(f => { if (!f) return; - + const cache = parseFileCache(f) this.filesIndex.set(file.path, cache); this.tagsMap.set(file.path, new Set(cache.tags)) @@ -410,7 +410,7 @@ export class Superstate extends Component { this.fileReloaded(file.path); this.broadcast('file', 'change', file.path) } - + public deleteTag(tag: string) { const contextCache = this.contextsIndex.get(tag); this.contextsIndex.delete(tag); @@ -459,7 +459,7 @@ export class Superstate extends Component { } if (fileCache) { - const allContextsWithFile = fileCache.contexts.map(f => this.contextsIndex.get(f)?.info).filter(f => f); + const allContextsWithFile = fileCache.contexts.map(f => this.contextsIndex.get(f)?.info).filter(f => f); this.addToContextStoreQueue(() => onMetadataChange(this.plugin, afile, allContextsWithFile)); this.reloadFile(afile); } @@ -473,7 +473,7 @@ export class Superstate extends Component { const newTFile = getAbstractFileAtPath(app, newPath); const oldFileCache = this.filesIndex.get(oldPath); if (!oldFileCache) { - + this.spacesMap.rename(oldPath, newPath) this.linksMap.rename(oldPath, newPath) this.linksMap.renameInverse(oldPath, newPath) @@ -481,7 +481,7 @@ export class Superstate extends Component { this.reloadFile(newTFile).then(f => this.broadcast('space')); return; } - + const fileCache = { ...this.filesIndex.get(oldPath), path: newPath, parent: newParentPath } this.filesIndex.set(newPath, fileCache); this.filesIndex.delete(oldPath); @@ -523,7 +523,7 @@ export class Superstate extends Component { } this.spacesMap.get(newFilePath).forEach(f => this.reloadSpace(f)); this.reloadFile(getAbstractFileAtPath(app, newFilePath)).then(f => this.broadcast('space')); - + this.addToContextStoreQueue(() => renameLinkInContexts(this.plugin, oldPath, newFilePath, allContextsWithLink).then(f => allContextsWithFile.forEach(c => this.reloadContext(c)))) } @@ -551,7 +551,7 @@ export class Superstate extends Component { this.addToContextStoreQueue(() => removeLinkInContexts(this.plugin, path, allContextsWithLink).then(f => allContextsWithFile.forEach(c => this.reloadContext(c)))) this.broadcast('space') } - + public async renameSpace(oldSpace: string, newSpace: string) { if (this.spacesIndex.has(oldSpace)) { this.spacesIndex.delete(oldSpace); @@ -570,7 +570,7 @@ export class Superstate extends Component { this.plugin.settings.cachedSpaces = this.allSpaces().map(f => f.name) this.plugin.saveSettings(); this.broadcast('space') - + } public async spacesSynced() { @@ -618,7 +618,7 @@ export class Superstate extends Component { } else { return; } - + } const spaceBackupFolder = normalizePath( `${app.vault.configDir}/plugins/make-md/backups` @@ -669,18 +669,18 @@ export class Superstate extends Component { this.broadcast('space', 'change', spaceName) } } - - + + } public async reloadFile(file: TAbstractFile, force?: boolean) : Promise { if (!file) return false; return this.indexer.reload<{cache: FileMetadataCache, changed: boolean}>({ type: 'file', path: file.path}).then(r => { - + const { changed, cache } = r; if (!changed && !force) { return false } - + this.filesIndex.set(file.path, cache); this.tagsMap.set(file.path, new Set(cache.tags)) this.contextsMap.set(file.path, new Set(cache.contexts)) @@ -690,20 +690,20 @@ export class Superstate extends Component { this.broadcast('space') } if (force) { - const allContextsWithFile = cache.contexts.map(f => this.contextsIndex.get(f)?.info).filter(f => f); + const allContextsWithFile = cache.contexts.map(f => this.contextsIndex.get(f)?.info).filter(f => f); this.addToContextStoreQueue(() => onMetadataChange(this.plugin, file, allContextsWithFile)); } - - if (cache.extension == 'svg' && this.plugin.settings.indexSVG) { + + if (cache.extension == 'svg' && this.plugin.settings.stickerSVG) { app.vault.read(file as TFile).then(f => { this.iconsCache.set(file.path, f) this.persister.store(file.path, f, 'icon') }) } - + this.fileReloaded(file.path); - - + + this.broadcast('file', 'change', file.path) return true; }); @@ -717,7 +717,7 @@ export class Superstate extends Component { if (!metadata) { return false; } - + let missingContexts : ContextInfo[] = []; let removedContexts : ContextInfo[] = []; this.contextsIndex.forEach(contextCache => { @@ -737,4 +737,4 @@ export class Superstate extends Component { } this.persister.store(path, serializeFileCache(metadata), 'file'); } -} \ No newline at end of file +} diff --git a/src/types/settings.ts b/src/types/settings.ts index 531a178..09e5be6 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -72,5 +72,7 @@ export interface MakeMDPluginSettings { fmKeyColor: string; fmKeySticker: string; openSpacesOnLaunch: boolean; - indexSVG: boolean; + stickerSVG: boolean; + stickerEmoji: boolean; + stickerIcon: boolean; }