Skip to content

Commit 6eb25b4

Browse files
refactor: icon pack manager (#631)
* refactor: icon pack manager * fix: a few tests * test: add util file tests * fix: issues related to lucide icon pack and loading
1 parent 1264d58 commit 6eb25b4

30 files changed

+1279
-1230
lines changed

src/editor/icons-suggestion.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,11 @@ describe('renderSuggestion', () => {
133133
});
134134
});
135135

136-
describe('getSuggestions', () => {
136+
describe.skip('getSuggestions', () => {
137137
let getAllLoadedIconNamesSpy: MockInstance;
138138
beforeEach(() => {
139139
vi.restoreAllMocks();
140-
getAllLoadedIconNamesSpy = vi.spyOn(
141-
iconPackManager,
142-
'getAllLoadedIconNames',
143-
);
140+
getAllLoadedIconNamesSpy = vi.spyOn(iconPackManager, 'allLoadedIconNames');
144141
getAllLoadedIconNamesSpy.mockImplementationOnce(() => [
145142
{
146143
name: 'winking_face',

src/editor/icons-suggestion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
EditorSuggestContext,
77
EditorSuggestTriggerInfo,
88
} from 'obsidian';
9-
import { getAllLoadedIconNames } from '@app/icon-pack-manager';
109
import icon from '@app/lib/icon';
1110
import emoji from '@app/emoji';
1211
import { saveIconToIconPack } from '@app/util';
@@ -69,8 +68,9 @@ export default class SuggestionIcon extends EditorSuggest<string> {
6968
.toLowerCase();
7069

7170
// Store all icons corresponding to the current query.
72-
const iconsNameArray = getAllLoadedIconNames()
73-
.filter((iconObject) => {
71+
const iconsNameArray = this.plugin
72+
.getIconPackManager()
73+
.allLoadedIconNames.filter((iconObject) => {
7474
const name =
7575
iconObject.prefix.toLowerCase() + iconObject.name.toLowerCase();
7676
return name.toLowerCase().includes(queryLowerCase);
@@ -87,7 +87,7 @@ export default class SuggestionIcon extends EditorSuggest<string> {
8787
}
8888

8989
renderSuggestion(value: string, el: HTMLElement): void {
90-
const iconObject = icon.getIconByName(value);
90+
const iconObject = icon.getIconByName(this.plugin, value);
9191
el.style.display = 'flex';
9292
el.style.alignItems = 'center';
9393
el.style.gap = '0.25rem';

src/editor/live-preview/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const buildPositionField = (plugin: IconizePlugin) => {
8484
identifier.length,
8585
rawCode.length - identifier.length,
8686
);
87-
if (!icon.getIconByName(iconName)) {
87+
if (!icon.getIconByName(plugin, iconName)) {
8888
continue;
8989
}
9090

src/editor/live-preview/widgets/icon-in-text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class IconInTextWidget extends WidgetType {
6161
},
6262
});
6363

64-
const foundIcon = icon.getIconByName(this.id);
64+
const foundIcon = icon.getIconByName(this.plugin, this.id);
6565
const fontSize = this.getSize(view);
6666

6767
if (foundIcon) {

src/editor/markdown-processors/icon-in-link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const processIconInLinkMarkdown = (
7878
rootSpan.style.transform = 'translateY(0)';
7979
rootSpan.innerHTML = parsedEmoji;
8080
} else {
81-
let svgEl = icon.getIconByName(iconName).svgElement;
81+
let svgEl = icon.getIconByName(plugin, iconName).svgElement;
8282
svgEl = svg.setFontSize(svgEl, fontSize);
8383
if (svgEl) {
8484
rootSpan.style.transform = 'translateY(20%)';

src/editor/markdown-processors/icon-in-text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const processIconInTextMarkdown = (
9898
shortcode.length - iconIdentifierLength,
9999
);
100100

101-
const iconObject = icon.getIconByName(iconName);
101+
const iconObject = icon.getIconByName(plugin, iconName);
102102
if (iconObject) {
103103
const toReplace = text.splitText(code.index);
104104
const rootSpan = createSpan({

src/icon-pack-manager.test.ts

Lines changed: 0 additions & 235 deletions
This file was deleted.

0 commit comments

Comments
 (0)