From 4513d68c9416ec8cce1b4424de4271bf52d4642e Mon Sep 17 00:00:00 2001 From: FlorianWoelki Date: Sun, 7 Jul 2024 09:55:21 +0200 Subject: [PATCH] refactor: rename IconFolderPlugin to IconizePlugin --- src/@types/internal-plugin-injector.ts | 6 ++--- src/editor/icons-suggestion.ts | 4 ++-- .../decorations/build-link-decorations.ts | 4 ++-- .../decorations/build-text-decorations.ts | 4 ++-- .../live-preview/plugins/icon-in-links.ts | 6 ++--- .../live-preview/plugins/icon-in-text.ts | 6 ++--- src/editor/live-preview/state.ts | 6 ++--- .../live-preview/widgets/icon-in-link.ts | 4 ++-- .../live-preview/widgets/icon-in-text.ts | 4 ++-- .../markdown-processors/icon-in-link.ts | 4 ++-- .../markdown-processors/icon-in-text.ts | 8 +++---- src/icon-pack-manager.ts | 11 ++++----- src/internal-plugins/bookmark.ts | 4 ++-- src/internal-plugins/outline.ts | 4 ++-- src/internal-plugins/starred.ts | 4 ++-- src/lib/custom-rule.ts | 22 +++++++++--------- src/lib/icon-tabs.ts | 14 +++++------ src/lib/icon-title.ts | 4 ++-- src/lib/icon.ts | 23 ++++++++----------- src/lib/util/dom.ts | 10 ++++---- src/lib/util/style.ts | 10 ++++---- src/main.ts | 2 +- .../0001-change-migrated-true-to-1.ts | 4 ++-- src/migrations/0002-order-custom-rules.ts | 4 ++-- .../0003-inheritance-to-custom-rule.ts | 4 ++-- .../0004-remove-none-emoji-option.ts | 4 ++-- ...0005-remove-downloaded-lucide-icon-pack.ts | 4 ++-- src/migrations/index.ts | 4 ++-- src/settings/helper.ts | 6 ++--- src/settings/ui/customIconPack.ts | 4 ++-- src/settings/ui/customIconRule.ts | 4 ++-- src/settings/ui/iconFolderSetting.ts | 6 ++--- src/settings/ui/index.ts | 6 ++--- src/settings/ui/predefinedIconPacks.ts | 4 ++-- src/ui/change-color-modal.ts | 6 ++--- src/ui/icon-pack-browser-modal.ts | 6 ++--- src/ui/icons-picker-modal.ts | 6 ++--- src/util.ts | 14 +++++------ 38 files changed, 122 insertions(+), 128 deletions(-) diff --git a/src/@types/internal-plugin-injector.ts b/src/@types/internal-plugin-injector.ts index 481c1a17..11c4ebb7 100644 --- a/src/@types/internal-plugin-injector.ts +++ b/src/@types/internal-plugin-injector.ts @@ -1,5 +1,5 @@ import { TAbstractFile, View, WorkspaceLeaf } from 'obsidian'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; interface FileExplorerWorkspaceLeaf extends WorkspaceLeaf { containerEl: HTMLElement; @@ -11,9 +11,9 @@ interface FileExplorerView extends View { } export default abstract class InternalPluginInjector { - protected plugin: IconFolderPlugin; + protected plugin: IconizePlugin; - constructor(plugin: IconFolderPlugin) { + constructor(plugin: IconizePlugin) { this.plugin = plugin; } diff --git a/src/editor/icons-suggestion.ts b/src/editor/icons-suggestion.ts index ac9e2a18..489d5b3c 100644 --- a/src/editor/icons-suggestion.ts +++ b/src/editor/icons-suggestion.ts @@ -10,12 +10,12 @@ import { getAllLoadedIconNames } from '../icon-pack-manager'; import icon from '../lib/icon'; import emoji from '../emoji'; import { saveIconToIconPack } from '@app/util'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; export default class SuggestionIcon extends EditorSuggest { constructor( app: App, - public plugin: IconFolderPlugin, + public plugin: IconizePlugin, ) { super(app); } diff --git a/src/editor/live-preview/decorations/build-link-decorations.ts b/src/editor/live-preview/decorations/build-link-decorations.ts index 11c655e6..4e5ed1d5 100644 --- a/src/editor/live-preview/decorations/build-link-decorations.ts +++ b/src/editor/live-preview/decorations/build-link-decorations.ts @@ -1,4 +1,4 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { Decoration, EditorView } from '@codemirror/view'; import { MarkdownView, editorInfoField } from 'obsidian'; import { RangeSetBuilder } from '@codemirror/state'; @@ -9,7 +9,7 @@ import { HeaderToken } from '@app/lib/util/text'; export const buildLinkDecorations = ( view: EditorView, - plugin: IconFolderPlugin, + plugin: IconizePlugin, ) => { const builder = new RangeSetBuilder(); const mdView = view.state.field(editorInfoField) as MarkdownView; diff --git a/src/editor/live-preview/decorations/build-text-decorations.ts b/src/editor/live-preview/decorations/build-text-decorations.ts index 99eba221..ad20e136 100644 --- a/src/editor/live-preview/decorations/build-text-decorations.ts +++ b/src/editor/live-preview/decorations/build-text-decorations.ts @@ -1,11 +1,11 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { Decoration, EditorView } from '@codemirror/view'; import { editorLivePreviewField } from 'obsidian'; import { IconInTextWidget } from '@app/editor/live-preview/widgets'; export const buildTextDecorations = ( view: EditorView, - plugin: IconFolderPlugin, + plugin: IconizePlugin, ) => { const ranges: [iconId: string, from: number, to: number][] = []; const iconInfo = view.state.field(plugin.positionField); diff --git a/src/editor/live-preview/plugins/icon-in-links.ts b/src/editor/live-preview/plugins/icon-in-links.ts index 3668fd0e..58f8a1d9 100644 --- a/src/editor/live-preview/plugins/icon-in-links.ts +++ b/src/editor/live-preview/plugins/icon-in-links.ts @@ -1,4 +1,4 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { DecorationSet, EditorView, @@ -7,11 +7,11 @@ import { } from '@codemirror/view'; import { buildLinkDecorations } from '@app/editor/live-preview/decorations'; -export const buildIconInLinksPlugin = (plugin: IconFolderPlugin) => { +export const buildIconInLinksPlugin = (plugin: IconizePlugin) => { return ViewPlugin.fromClass( class { decorations: DecorationSet; - plugin: IconFolderPlugin; + plugin: IconizePlugin; constructor(view: EditorView) { this.plugin = plugin; diff --git a/src/editor/live-preview/plugins/icon-in-text.ts b/src/editor/live-preview/plugins/icon-in-text.ts index 9364f9c1..75d6c5ab 100644 --- a/src/editor/live-preview/plugins/icon-in-text.ts +++ b/src/editor/live-preview/plugins/icon-in-text.ts @@ -1,4 +1,4 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { Decoration, DecorationSet, @@ -8,11 +8,11 @@ import { } from '@codemirror/view'; import { buildTextDecorations } from '@app/editor/live-preview/decorations'; -export const buildIconInTextPlugin = (plugin: IconFolderPlugin) => { +export const buildIconInTextPlugin = (plugin: IconizePlugin) => { return ViewPlugin.fromClass( class IconPlugin { decorations: DecorationSet; - plugin: IconFolderPlugin; + plugin: IconizePlugin; constructor(view: EditorView) { this.plugin = plugin; diff --git a/src/editor/live-preview/state.ts b/src/editor/live-preview/state.ts index d2bd2969..3a858c5d 100644 --- a/src/editor/live-preview/state.ts +++ b/src/editor/live-preview/state.ts @@ -11,7 +11,7 @@ import { RangeValue, StateField, } from '@codemirror/state'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import emoji from '@app/emoji'; export type PositionField = StateField>; @@ -23,7 +23,7 @@ type UpdateRangeFunc = ( remove: boolean, ) => void; -function checkForSourceMode(plugin: IconFolderPlugin): boolean { +function checkForSourceMode(plugin: IconizePlugin): boolean { let isSourceMode = false; // Iterate over all leaves to check if any is in source mode plugin.app.workspace.iterateAllLeaves((leaf) => { @@ -55,7 +55,7 @@ class IconPosition extends RangeValue { * Builds a position field for the editor state. This field will track the * positions of the icons in the document. **/ -export const buildPositionField = (plugin: IconFolderPlugin) => { +export const buildPositionField = (plugin: IconizePlugin) => { /** * Checks the ranges of the icons in the document. If the range is not * excluded, the range is added to the range set. If the range is excluded, diff --git a/src/editor/live-preview/widgets/icon-in-link.ts b/src/editor/live-preview/widgets/icon-in-link.ts index 7ad2a7a3..285bd053 100644 --- a/src/editor/live-preview/widgets/icon-in-link.ts +++ b/src/editor/live-preview/widgets/icon-in-link.ts @@ -6,12 +6,12 @@ import { HeaderToken, } from '@app/lib/util/text'; import svg from '@app/lib/util/svg'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { WidgetType } from '@codemirror/view'; export class IconInLinkWidget extends WidgetType { constructor( - private plugin: IconFolderPlugin, + private plugin: IconizePlugin, private iconData: Icon | string, private path: string, private headerType: HeaderToken | null, diff --git a/src/editor/live-preview/widgets/icon-in-text.ts b/src/editor/live-preview/widgets/icon-in-text.ts index 06825e1d..f280b14f 100644 --- a/src/editor/live-preview/widgets/icon-in-text.ts +++ b/src/editor/live-preview/widgets/icon-in-text.ts @@ -6,7 +6,7 @@ import { calculateFontTextSize, calculateHeaderSize, } from '@app/lib/util/text'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { EditorView, WidgetType } from '@codemirror/view'; export class IconInTextWidget extends WidgetType { @@ -14,7 +14,7 @@ export class IconInTextWidget extends WidgetType { private end = -1; constructor( - public plugin: IconFolderPlugin, + public plugin: IconizePlugin, public id: string, ) { super(); diff --git a/src/editor/markdown-processors/icon-in-link.ts b/src/editor/markdown-processors/icon-in-link.ts index b35c3895..4a2b5f2c 100644 --- a/src/editor/markdown-processors/icon-in-link.ts +++ b/src/editor/markdown-processors/icon-in-link.ts @@ -8,11 +8,11 @@ import { HTMLHeader, isHeader, } from '@app/lib/util/text'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { MarkdownPostProcessorContext } from 'obsidian'; export const processIconInLinkMarkdown = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, element: HTMLElement, ctx: MarkdownPostProcessorContext, ) => { diff --git a/src/editor/markdown-processors/icon-in-text.ts b/src/editor/markdown-processors/icon-in-text.ts index b03f6573..c46c4d0a 100644 --- a/src/editor/markdown-processors/icon-in-text.ts +++ b/src/editor/markdown-processors/icon-in-text.ts @@ -9,10 +9,10 @@ import { calculateHeaderSize, isHeader, } from '@app/lib/util/text'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import emoji from '@app/emoji'; -export const createIconShortcodeRegex = (plugin: IconFolderPlugin): RegExp => { +export const createIconShortcodeRegex = (plugin: IconizePlugin): RegExp => { return new RegExp( `(${ plugin.getSettings().iconIdentifier @@ -24,7 +24,7 @@ export const createIconShortcodeRegex = (plugin: IconFolderPlugin): RegExp => { }; const createTreeWalker = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, root: HTMLElement, ): TreeWalker => { return document.createTreeWalker(root, NodeFilter.SHOW_ALL, { @@ -76,7 +76,7 @@ const checkForTextNodes = ( }; export const processIconInTextMarkdown = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, element: HTMLElement, ) => { // Ignore if codeblock diff --git a/src/icon-pack-manager.ts b/src/icon-pack-manager.ts index e738062b..50c976b3 100644 --- a/src/icon-pack-manager.ts +++ b/src/icon-pack-manager.ts @@ -4,7 +4,7 @@ import { getFileFromJSZipFile, readZipFile } from './zip-util'; import JSZip from 'jszip'; import config from '@app/config'; import { logger } from '@app/lib/logger'; -import IconFolderPlugin from './main'; +import IconizePlugin from './main'; import { getExtraPath } from './icon-packs'; export const NATIVE_LUCIDE_ICON_PACK_NAME = 'lucide-icons'; @@ -345,10 +345,7 @@ export const createIconPackPrefix = (iconPackName: string): string => { ); }; -export const loadUsedIcons = async ( - plugin: IconFolderPlugin, - icons: string[], -) => { +export const loadUsedIcons = async (plugin: IconizePlugin, icons: string[]) => { const iconPacks = [ ...(await listPath(plugin)).folders.map((iconPack) => iconPack.split('/').pop(), @@ -379,7 +376,7 @@ export const nextIdentifier = (iconName: string) => { }; export const loadIcon = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconPackNames: string[], iconName: string, ): Promise => { @@ -558,7 +555,7 @@ export const addIconToIconPack = ( }; export const removeIconFromIconPackDirectory = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconPackName: string, iconName: string, ): Promise => { diff --git a/src/internal-plugins/bookmark.ts b/src/internal-plugins/bookmark.ts index 7e6f15fb..1eb658da 100644 --- a/src/internal-plugins/bookmark.ts +++ b/src/internal-plugins/bookmark.ts @@ -4,7 +4,7 @@ import InternalPluginInjector from '@app/@types/internal-plugin-injector'; import { BookmarkItem, BookmarkItemValue } from '@app/@types/obsidian'; import dom from '@lib/util/dom'; import icon from '@lib/icon'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import config from '@app/config'; import { DEFAULT_FILE_ICON, DEFAULT_FOLDER_ICON } from '@app/util'; @@ -13,7 +13,7 @@ interface BookmarksView extends View { } export default class BookmarkInternalPlugin extends InternalPluginInjector { - constructor(plugin: IconFolderPlugin) { + constructor(plugin: IconizePlugin) { super(plugin); } diff --git a/src/internal-plugins/outline.ts b/src/internal-plugins/outline.ts index 2f8bf92e..743792d8 100644 --- a/src/internal-plugins/outline.ts +++ b/src/internal-plugins/outline.ts @@ -3,7 +3,7 @@ import { createIconShortcodeRegex } from '@app/editor/markdown-processors'; import svg from '@app/lib/util/svg'; import icon from '@app/lib/icon'; import { LoggerPrefix, logger } from '@app/lib/logger'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { View } from 'obsidian'; const TREE_ITEM_CLASS = 'tree-item-self'; @@ -16,7 +16,7 @@ interface OutlineView extends View { } export default class OutlineInternalPlugin extends InternalPluginInjector { - constructor(plugin: IconFolderPlugin) { + constructor(plugin: IconizePlugin) { super(plugin); } diff --git a/src/internal-plugins/starred.ts b/src/internal-plugins/starred.ts index e782d629..2b8f0b4c 100644 --- a/src/internal-plugins/starred.ts +++ b/src/internal-plugins/starred.ts @@ -5,7 +5,7 @@ import { StarredFile } from '@app/@types/obsidian'; import dom from '@lib/util/dom'; import icon from '@lib/icon'; import config from '@app/config'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; interface StarredView extends View { itemLookup: WeakMap; @@ -15,7 +15,7 @@ interface StarredView extends View { * @deprecated After obsidian 1.2.6 in favor of the bookmarks plugin. */ export default class StarredInternalPlugin extends InternalPluginInjector { - constructor(plugin: IconFolderPlugin) { + constructor(plugin: IconizePlugin) { super(plugin); } diff --git a/src/lib/custom-rule.ts b/src/lib/custom-rule.ts index 579648a8..dc2d5b4b 100644 --- a/src/lib/custom-rule.ts +++ b/src/lib/custom-rule.ts @@ -1,5 +1,5 @@ import { Plugin, TAbstractFile } from 'obsidian'; -import IconFolderPlugin from '../main'; +import IconizePlugin from '../main'; import { CustomRule } from '../settings/data'; import dom from './util/dom'; import { getFileItemTitleEl } from '../util'; @@ -56,11 +56,11 @@ const isApplicable = async ( /** * Removes the icon from the custom rule from all the files and folders, if applicable. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param rule CustomRule where the icons will be removed based on this rule. */ const removeFromAllFiles = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, rule: CustomRule, ): Promise => { const nodesWithIcon = document.querySelectorAll( @@ -90,10 +90,10 @@ const removeFromAllFiles = async ( /** * Gets all the custom rules sorted by their order property in ascending order. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @returns CustomRule array sorted by their order property in ascending order. */ -const getSortedRules = (plugin: IconFolderPlugin): CustomRule[] => { +const getSortedRules = (plugin: IconizePlugin): CustomRule[] => { return plugin.getSettings().rules.sort((a, b) => a.order - b.order); }; @@ -101,11 +101,11 @@ const getSortedRules = (plugin: IconFolderPlugin): CustomRule[] => { * Tries to add all specific custom rule icons to all registered files and directories. * It does that by calling the {@link add} function. Custom rules should have the lowest * priority and will get ignored if an icon already exists in the file or directory. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param rule CustomRule that will be applied, if applicable, to all files and folders. */ const addToAllFiles = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, rule: CustomRule, ): Promise => { const fileItems = await getFileItems(plugin, rule); @@ -117,7 +117,7 @@ const addToAllFiles = async ( /** * Tries to add the icon of the custom rule to a file or folder. This function also checks * if the file type matches the `for` property of the custom rule. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param rule CustomRule that will be used to check if the rule is applicable to the file * or directory. * @param file TAbstractFile that will be used to possibly create the icon for. @@ -125,7 +125,7 @@ const addToAllFiles = async ( * @returns A promise that resolves to `true` if the icon was added, `false` otherwise. */ const add = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, rule: CustomRule, file: TAbstractFile, container?: HTMLElement, @@ -180,12 +180,12 @@ const doesMatchPath = (rule: CustomRule, path: string): boolean => { /** * Gets all the file items that can be applied to the specific custom rule. - * @param plugin Instance of IconFolderPlugin. + * @param plugin Instance of IconizePlugin. * @param rule Custom rule that will be checked for. * @returns A promise that resolves to an array of file items that match the custom rule. */ const getFileItems = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, rule: CustomRule, ): Promise => { const result: FileItem[] = []; diff --git a/src/lib/icon-tabs.ts b/src/lib/icon-tabs.ts index 2eaa0536..67ec62ae 100644 --- a/src/lib/icon-tabs.ts +++ b/src/lib/icon-tabs.ts @@ -1,5 +1,5 @@ import { TFile } from 'obsidian'; -import IconFolderPlugin, { FolderIconObject } from '@app/main'; +import IconizePlugin, { FolderIconObject } from '@app/main'; import { DEFAULT_FILE_ICON, getAllOpenedFiles } from '@app/util'; import { TabHeaderLeaf } from '@app/@types/obsidian'; import customRule from './custom-rule'; @@ -8,12 +8,12 @@ import dom from './util/dom'; /** * Gets the tab leaves of a specific file path by looping through all opened files and * checking if the file path matches. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param path String of the file path to get the tab leaf of. * @returns TabHeaderLeaf array that includes all tab leaves of the file path. */ const getTabLeavesOfFilePath = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, path: string, ): TabHeaderLeaf[] => { const openedFiles = getAllOpenedFiles(plugin); @@ -40,13 +40,13 @@ interface AddOptions { /** * Adds an icon to the tab and its container. This function respects the * custom rules and individually icon set. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param file TFile instance of the file to add the icon to. * @param iconContainer HTMLElement where the icon will be added to. * @param options AddOptions for the add function which can optionally be used. */ const add = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, file: TFile, iconContainer: HTMLElement, options?: AddOptions, @@ -106,12 +106,12 @@ const add = async ( /** * Updates the icon in the tab and container by setting calling the `setIconForNode` * function and removing the margin from the icon container. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param iconName String of the icon name to update to. * @param iconContainer HTMLElement where the icon is located and will be updated. */ const update = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconName: string, iconContainer: HTMLElement, ) => { diff --git a/src/lib/icon-title.ts b/src/lib/icon-title.ts index bbc9b143..ee0dc50a 100644 --- a/src/lib/icon-title.ts +++ b/src/lib/icon-title.ts @@ -1,4 +1,4 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import config from '@app/config'; import emoji from '@app/emoji'; import svg from './util/svg'; @@ -13,7 +13,7 @@ interface Options { } const add = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, inlineTitleEl: HTMLElement, svgElement: string, options?: Options, diff --git a/src/lib/icon.ts b/src/lib/icon.ts index c53de2b1..986cfb7c 100644 --- a/src/lib/icon.ts +++ b/src/lib/icon.ts @@ -1,6 +1,6 @@ import { ExplorerView, TabHeaderLeaf } from '@app/@types/obsidian'; import emoji from '@app/emoji'; -import IconFolderPlugin, { FolderIconObject } from '@app/main'; +import IconizePlugin, { FolderIconObject } from '@app/main'; import customRule from './custom-rule'; import dom from './util/dom'; import iconTabs from './icon-tabs'; @@ -23,7 +23,7 @@ import { IconCache } from './icon-cache'; import { logger } from './logger'; const checkMissingIcons = async ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, data: [string, string | FolderIconObject][], ): Promise => { const missingIcons: Set = new Set(); @@ -170,7 +170,7 @@ const checkMissingIcons = async ( * This function adds all the possible icons to the corresponding nodes. It * adds the icons, that are defined in the data as a basic string to the nodes * and the custom rule icons. - * @param plugin Instance of IconFolderPlugin. + * @param plugin Instance of IconizePlugin. * @param data Data that will be used to add all the icons to the nodes. * @param registeredFileExplorers A WeakSet of file explorers that are being used as a * cache for already handled file explorers. @@ -178,7 +178,7 @@ const checkMissingIcons = async ( * explorer. */ const addAll = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, data: [string, string | FolderIconObject][], registeredFileExplorers: WeakSet, callback?: () => void, @@ -252,14 +252,11 @@ const addAll = ( /** * Gets the icon of a given path. This function returns the first occurrence of an icon. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @param path Path to get the icon of. * @returns The icon of the path if it exists, undefined otherwise. */ -const getByPath = ( - plugin: IconFolderPlugin, - path: string, -): string | undefined => { +const getByPath = (plugin: IconizePlugin, path: string): string | undefined => { if (path === 'settings' || path === 'migrated') { return undefined; } @@ -293,11 +290,11 @@ interface IconWithPath { /** * Gets all the icons with their paths as an object. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @returns An object that consists of the path and the icon name for the data * or custom rule. */ -const getAllWithPath = (plugin: IconFolderPlugin): IconWithPath[] => { +const getAllWithPath = (plugin: IconizePlugin): IconWithPath[] => { const result: IconWithPath[] = []; Object.keys(plugin.getData()).forEach((path) => { if (path === 'settings' || path === 'migrated') { @@ -341,12 +338,12 @@ const getIconByName = (iconNameWithPrefix: string): Icon | null => { /** * Returns the {@link Icon} for the given path. - * @param plugin IconFolderPlugin instance. + * @param plugin IconizePlugin instance. * @param path String which is the path to get the icon of. * @returns Icon or Emoji as string if it exists, `null` otherwise. */ const getIconByPath = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, path: string, ): Icon | string | null => { const iconNameWithPrefix = getByPath(plugin, path); diff --git a/src/lib/util/dom.ts b/src/lib/util/dom.ts index 74aea10c..2f624053 100644 --- a/src/lib/util/dom.ts +++ b/src/lib/util/dom.ts @@ -1,5 +1,5 @@ import config from '@app/config'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { logger } from '@app/lib/logger'; import { getSvgFromLoadedIcon, nextIdentifier } from '@app/icon-pack-manager'; import style from './style'; @@ -46,13 +46,13 @@ const removeIconInPath = (path: string, options?: RemoveOptions): void => { /** * Sets an icon or emoji for an HTMLElement based on the specified icon name and color. * The function manipulates the specified node inline. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @param iconName Name of the icon or emoji to add. * @param node HTMLElement to which the icon or emoji will be added. * @param color Optional color of the icon to add. */ const setIconForNode = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconName: string, node: HTMLElement, color?: string, @@ -95,13 +95,13 @@ interface CreateOptions { /** * Creates an icon node for the specified path and inserts it to the DOM. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @param path Path for which the icon node will be created. * @param iconName Name of the icon or emoji to add. * @param color Optional color of the icon to add. */ const createIconNode = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, path: string, iconName: string, options?: CreateOptions, diff --git a/src/lib/util/style.ts b/src/lib/util/style.ts index 6799dce1..ac6b8e35 100644 --- a/src/lib/util/style.ts +++ b/src/lib/util/style.ts @@ -3,7 +3,7 @@ // dependency is the `svg` library. import emoji from '../../emoji'; -import IconFolderPlugin from '../../main'; +import IconizePlugin from '../../main'; import svg from './svg'; import { getFileItemTitleEl } from '../../util'; @@ -29,13 +29,13 @@ const setMargin = (el: HTMLElement, margin: Margin): HTMLElement => { * Applies all stylings to the specified svg icon string and applies styling to the node * (container). The styling to the specified element is only modified when it is an emoji * or extra margin is defined in the settings. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @param iconString SVG that will be used to apply the svg styles to. * @param el Node for manipulating the style. * @returns Icon svg string with the manipulate style attributes. */ const applyAll = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconString: string, container: HTMLElement, ): string => { @@ -66,12 +66,12 @@ const applyAll = ( /** * Refreshes all the styles of all the applied icons where a `.iconize-icon` * class is defined. This function only modifies the styling of the node. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @param applyStyles Function that is getting called when the icon node is found and * typically applies all the styles to the icon. */ const refreshIconNodes = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, applyStyles = applyAll, ): void => { const fileExplorers = plugin.app.workspace.getLeavesOfType('file-explorer'); diff --git a/src/main.ts b/src/main.ts index 7ca1b0d3..18e7ae00 100644 --- a/src/main.ts +++ b/src/main.ts @@ -68,7 +68,7 @@ export interface FolderIconObject { iconColor?: string; } -export default class IconFolderPlugin extends Plugin { +export default class IconizePlugin extends Plugin { private data: Record< string, boolean | string | IconFolderSettings | FolderIconObject diff --git a/src/migrations/0001-change-migrated-true-to-1.ts b/src/migrations/0001-change-migrated-true-to-1.ts index e67aa97b..a672e621 100644 --- a/src/migrations/0001-change-migrated-true-to-1.ts +++ b/src/migrations/0001-change-migrated-true-to-1.ts @@ -1,7 +1,7 @@ import { Notice } from 'obsidian'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; -export default async function migrate(plugin: IconFolderPlugin): Promise { +export default async function migrate(plugin: IconizePlugin): Promise { // Migration for new syncing mechanism. if (plugin.getSettings().migrated === 1) { new Notice( diff --git a/src/migrations/0002-order-custom-rules.ts b/src/migrations/0002-order-custom-rules.ts index 80cd771d..e60541f3 100644 --- a/src/migrations/0002-order-custom-rules.ts +++ b/src/migrations/0002-order-custom-rules.ts @@ -1,6 +1,6 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; -export default async function migrate(plugin: IconFolderPlugin): Promise { +export default async function migrate(plugin: IconizePlugin): Promise { // Migration for new order functionality of custom rules. if (plugin.getSettings().migrated === 2) { // Sorting alphabetically was the default behavior before. diff --git a/src/migrations/0003-inheritance-to-custom-rule.ts b/src/migrations/0003-inheritance-to-custom-rule.ts index 24c5357a..1c465494 100644 --- a/src/migrations/0003-inheritance-to-custom-rule.ts +++ b/src/migrations/0003-inheritance-to-custom-rule.ts @@ -1,6 +1,6 @@ import config from '@app/config'; import customRule from '@app/lib/custom-rule'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { CustomRule } from '@app/settings/data'; import { Notice } from 'obsidian'; @@ -10,7 +10,7 @@ interface FolderIconObject { iconColor?: string; } -export default async function migrate(plugin: IconFolderPlugin): Promise { +export default async function migrate(plugin: IconizePlugin): Promise { // Migration for inheritance to custom rule. if (plugin.getSettings().migrated === 3) { let hasRemovedInheritance = false; diff --git a/src/migrations/0004-remove-none-emoji-option.ts b/src/migrations/0004-remove-none-emoji-option.ts index f9ab6daf..affac8fd 100644 --- a/src/migrations/0004-remove-none-emoji-option.ts +++ b/src/migrations/0004-remove-none-emoji-option.ts @@ -1,6 +1,6 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; -export default async function migrate(plugin: IconFolderPlugin): Promise { +export default async function migrate(plugin: IconizePlugin): Promise { if (plugin.getSettings().migrated === 4) { if ((plugin.getSettings().emojiStyle as string) === 'none') { plugin.getSettings().emojiStyle = 'native'; diff --git a/src/migrations/0005-remove-downloaded-lucide-icon-pack.ts b/src/migrations/0005-remove-downloaded-lucide-icon-pack.ts index 46a0019d..db6a0be3 100644 --- a/src/migrations/0005-remove-downloaded-lucide-icon-pack.ts +++ b/src/migrations/0005-remove-downloaded-lucide-icon-pack.ts @@ -2,9 +2,9 @@ import { deleteIconPack, NATIVE_LUCIDE_ICON_PACK_NAME, } from '@app/icon-pack-manager'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; -export default async function migrate(plugin: IconFolderPlugin): Promise { +export default async function migrate(plugin: IconizePlugin): Promise { if (plugin.getSettings().migrated === 5) { await deleteIconPack(plugin, NATIVE_LUCIDE_ICON_PACK_NAME); plugin.getSettings().migrated++; diff --git a/src/migrations/index.ts b/src/migrations/index.ts index a12a1c70..e099cc2e 100644 --- a/src/migrations/index.ts +++ b/src/migrations/index.ts @@ -1,11 +1,11 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import migrate0001 from './0001-change-migrated-true-to-1'; import migrate0002 from './0002-order-custom-rules'; import migrate0003 from './0003-inheritance-to-custom-rule'; import migrate0004 from './0004-remove-none-emoji-option'; import migrate0005 from './0005-remove-downloaded-lucide-icon-pack'; -export const migrate = async (plugin: IconFolderPlugin): Promise => { +export const migrate = async (plugin: IconizePlugin): Promise => { // eslint-disable-next-line // @ts-ignore - Required because an older version of the plugin saved the `migrated` // property as a boolean instead of a number. diff --git a/src/settings/helper.ts b/src/settings/helper.ts index ea37d67a..a39e8c30 100644 --- a/src/settings/helper.ts +++ b/src/settings/helper.ts @@ -1,15 +1,15 @@ import customRule from '@lib/custom-rule'; import style from '@lib/util/style'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { getFileItemTitleEl } from '@app/util'; import svg from '@app/lib/util/svg'; /** * Helper function that refreshes the style of all the icons that are defined * or in a custom rule involved. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. */ -const refreshStyleOfIcons = async (plugin: IconFolderPlugin): Promise => { +const refreshStyleOfIcons = async (plugin: IconizePlugin): Promise => { // Refreshes the icon style for all normally added icons. style.refreshIconNodes(plugin); diff --git a/src/settings/ui/customIconPack.ts b/src/settings/ui/customIconPack.ts index 2d68e2ac..a96d30d8 100644 --- a/src/settings/ui/customIconPack.ts +++ b/src/settings/ui/customIconPack.ts @@ -9,7 +9,7 @@ import { getAllIconPacks, NATIVE_LUCIDE_ICON_PACK_NAME, } from '@app/icon-pack-manager'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { readFileSync } from '@app/util'; export default class CustomIconPackSetting extends IconFolderSetting { @@ -20,7 +20,7 @@ export default class CustomIconPackSetting extends IconFolderSetting { private refreshDisplay: () => void; constructor( - plugin: IconFolderPlugin, + plugin: IconizePlugin, containerEl: HTMLElement, refreshDisplay: () => void, ) { diff --git a/src/settings/ui/customIconRule.ts b/src/settings/ui/customIconRule.ts index c4b9616e..139e7a07 100644 --- a/src/settings/ui/customIconRule.ts +++ b/src/settings/ui/customIconRule.ts @@ -10,7 +10,7 @@ import { } from 'obsidian'; import IconFolderSetting from './iconFolderSetting'; import IconsPickerModal from '@app/ui/icons-picker-modal'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { getAllOpenedFiles, getFileItemTitleEl, @@ -33,7 +33,7 @@ export default class CustomIconRuleSetting extends IconFolderSetting { private refreshDisplay: () => void; constructor( - plugin: IconFolderPlugin, + plugin: IconizePlugin, containerEl: HTMLElement, app: App, refreshDisplay: () => void, diff --git a/src/settings/ui/iconFolderSetting.ts b/src/settings/ui/iconFolderSetting.ts index f58dda2c..71d6c6b4 100644 --- a/src/settings/ui/iconFolderSetting.ts +++ b/src/settings/ui/iconFolderSetting.ts @@ -1,10 +1,10 @@ -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; export default abstract class IconFolderSetting { - protected plugin: IconFolderPlugin; + protected plugin: IconizePlugin; protected containerEl: HTMLElement; - constructor(plugin: IconFolderPlugin, containerEl: HTMLElement) { + constructor(plugin: IconizePlugin, containerEl: HTMLElement) { this.plugin = plugin; this.containerEl = containerEl; } diff --git a/src/settings/ui/index.ts b/src/settings/ui/index.ts index 58e41aea..059f34f5 100644 --- a/src/settings/ui/index.ts +++ b/src/settings/ui/index.ts @@ -1,5 +1,5 @@ import { App, PluginSettingTab } from 'obsidian'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import CustomIconPackSetting from './customIconPack'; import CustomIconRuleSetting from './customIconRule'; import EmojiStyleSetting from './emojiStyle'; @@ -19,9 +19,9 @@ import IconIdentifierSetting from './iconIdentifier'; import DebugMode from './debugMode'; export default class IconFolderSettings extends PluginSettingTab { - private plugin: IconFolderPlugin; + private plugin: IconizePlugin; - constructor(app: App, plugin: IconFolderPlugin) { + constructor(app: App, plugin: IconizePlugin) { super(app, plugin); this.plugin = plugin; diff --git a/src/settings/ui/predefinedIconPacks.ts b/src/settings/ui/predefinedIconPacks.ts index 3a73a7cb..82ffbe9d 100644 --- a/src/settings/ui/predefinedIconPacks.ts +++ b/src/settings/ui/predefinedIconPacks.ts @@ -1,14 +1,14 @@ import { App, Setting } from 'obsidian'; import IconFolderSetting from './iconFolderSetting'; import IconPackBrowserModal from '@app/ui/icon-pack-browser-modal'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; export default class PredefinedIconPacksSetting extends IconFolderSetting { private app: App; private refreshDisplay: () => void; constructor( - plugin: IconFolderPlugin, + plugin: IconizePlugin, containerEl: HTMLElement, app: App, refreshDisplay: () => void, diff --git a/src/ui/change-color-modal.ts b/src/ui/change-color-modal.ts index 03516659..ed5bb47f 100644 --- a/src/ui/change-color-modal.ts +++ b/src/ui/change-color-modal.ts @@ -1,15 +1,15 @@ import { App, Modal, ColorComponent, ButtonComponent, Notice } from 'obsidian'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import svg from '@app/lib/util/svg'; import dom from '@app/lib/util/dom'; export default class ChangeColorModal extends Modal { - private plugin: IconFolderPlugin; + private plugin: IconizePlugin; private path: string; private usedColor?: string; - constructor(app: App, plugin: IconFolderPlugin, path: string) { + constructor(app: App, plugin: IconizePlugin, path: string) { super(app); this.plugin = plugin; this.path = path; diff --git a/src/ui/icon-pack-browser-modal.ts b/src/ui/icon-pack-browser-modal.ts index 1118010b..6a340422 100644 --- a/src/ui/icon-pack-browser-modal.ts +++ b/src/ui/icon-pack-browser-modal.ts @@ -6,13 +6,13 @@ import { getAllIconPacks, } from '@app/icon-pack-manager'; import iconPacks, { IconPack } from '@app/icon-packs'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import { downloadZipFile } from '@app/zip-util'; export default class IconPackBrowserModal extends FuzzySuggestModal { - private plugin: IconFolderPlugin; + private plugin: IconizePlugin; - constructor(app: App, plugin: IconFolderPlugin) { + constructor(app: App, plugin: IconizePlugin) { super(app); this.plugin = plugin; diff --git a/src/ui/icons-picker-modal.ts b/src/ui/icons-picker-modal.ts index 56ce139e..c644daa4 100644 --- a/src/ui/icons-picker-modal.ts +++ b/src/ui/icons-picker-modal.ts @@ -1,5 +1,5 @@ import { App, FuzzyMatch, FuzzySuggestModal } from 'obsidian'; -import IconFolderPlugin from '@app/main'; +import IconizePlugin from '@app/main'; import emoji from '@app/emoji'; import { doesIconExists, @@ -19,7 +19,7 @@ export interface Icon { } export default class IconsPickerModal extends FuzzySuggestModal { - private plugin: IconFolderPlugin; + private plugin: IconizePlugin; private path: string; private renderIndex = 0; @@ -28,7 +28,7 @@ export default class IconsPickerModal extends FuzzySuggestModal { public onSelect: (iconName: string) => void | undefined; - constructor(app: App, plugin: IconFolderPlugin, path: string) { + constructor(app: App, plugin: IconizePlugin, path: string) { super(app); this.plugin = plugin; this.path = path; diff --git a/src/util.ts b/src/util.ts index 49819941..628f963a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,7 +8,7 @@ import { removeIconFromIconPackDirectory, } from '@app/icon-pack-manager'; import { FileItem, FileWithLeaf } from './@types/obsidian'; -import IconFolderPlugin from './main'; +import IconizePlugin from './main'; // Default obsidian file icon. export const DEFAULT_FILE_ICON = @@ -37,10 +37,10 @@ export const readFileSync = async (file: File): Promise => { /** * Gets all the currently opened files by getting the markdown leaves and then checking * for the `file` property in the view. This also returns the leaf of the file. - * @param plugin Instance of the IconFolderPlugin. + * @param plugin Instance of the IconizePlugin. * @returns An array of {@link FileWithLeaf} objects. */ -export const getAllOpenedFiles = (plugin: IconFolderPlugin): FileWithLeaf[] => { +export const getAllOpenedFiles = (plugin: IconizePlugin): FileWithLeaf[] => { return plugin.app.workspace .getLeavesOfType('markdown') .reduce((prev, curr) => { @@ -73,11 +73,11 @@ export const getFileItemInnerTitleEl = (fileItem: FileItem): HTMLElement => { /** * A utility function which will add the icon to the icon pack and then extract the icon * to the icon pack. - * @param plugin IconFolderPlugin that will be used for extracting the icon. + * @param plugin IconizePlugin that will be used for extracting the icon. * @param iconNameWithPrefix String that will be used to add the icon to the icon pack. */ export const saveIconToIconPack = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconNameWithPrefix: string, ): void => { const iconNextIdentifier = nextIdentifier(iconNameWithPrefix); @@ -100,11 +100,11 @@ export const saveIconToIconPack = ( /** * A utility function which will remove the icon from the icon pack by removing the icon * file from the icon pack directory. - * @param plugin IconFolderPlugin that will be used for removing the icon. + * @param plugin IconizePlugin that will be used for removing the icon. * @param iconNameWithPrefix String that will be used to remove the icon from the icon pack. */ export const removeIconFromIconPack = ( - plugin: IconFolderPlugin, + plugin: IconizePlugin, iconNameWithPrefix: string, ): void => { const identifier = nextIdentifier(iconNameWithPrefix);