Skip to content

Commit

Permalink
Improve TypeScript code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmostellar committed Feb 22, 2024
1 parent 3607ee6 commit 3a18aca
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions rollup.config.js
Expand Up @@ -25,8 +25,8 @@ export default {
}),
alias({
entires: [
{ find: "@events", replacement: "./src/events" },
{ find: "@settings", replacement: "./src/settings" },
{ find: "@src", replacement: "./src/" },
{ find: "@components", replacement: "./src/components/" },
],
}),
commonjs({
Expand Down
File renamed without changes.
32 changes: 16 additions & 16 deletions src/main.ts
@@ -1,27 +1,27 @@
import { Plugin } from "obsidian";

import { FormattoEditorMenu } from "@events/editorMenu";
import { FormattoSettingTab } from "@settings/settingTab";
import { DEFAULT_SETTINGS } from "@settings/settingTypes";
import { FormattoCommands } from "@src/obsidian/commands";
import { FormattoEditorMenu } from "@src/obsidian/events/editorMenu";
import { FormattoIcons } from "@src/obsidian/icons/icons";
import { FormattoRibbonIcons } from "@src/obsidian/ribbonIcons";
import { FormattoSettingTab } from "@src/obsidian/settings/settingTab";
import { DEFAULT_SETTINGS } from "@src/obsidian/settings/settingTypes";
import { FormattoUtils } from "@src/obsidian/utils";

import __wbg_init from "../wasm/pkg/formatto_wasm";
import formatto_wasm from "../wasm/pkg/formatto_wasm_bg.wasm";
import { FormattoCommands } from "./commands/commands";
import { CustomIcons } from "./etc/icons/customIcons";
import { RibbonIcons } from "./etc/ribbonIcons";
import { FormattoUtils } from "./utils";

import type { FormattoPluginSettings } from "@settings/settingTypes";
import type { FormattoPluginSettings } from "@src/obsidian/settings/settingTypes";

/** Entry Point. */
export default class FormattoPlugin extends Plugin {
settings: FormattoPluginSettings;

utils = new FormattoUtils(this);
private iconCreator = new CustomIcons();
private ribbonIcon = new RibbonIcons(this);
private eventsMenuCreator = new FormattoEditorMenu(this);
private commandCreator = new FormattoCommands(this);
private icons = new FormattoIcons();
private ribbonIcons = new FormattoRibbonIcons(this);
private editorMenus = new FormattoEditorMenu(this);
private commands = new FormattoCommands(this);

/** Load and Save Settings */
async loadSettings() {
Expand All @@ -47,10 +47,10 @@ export default class FormattoPlugin extends Plugin {

this.addSettingTab(new FormattoSettingTab(this.app, this));

this.iconCreator.registerIcons();
this.ribbonIcon.registerRibbonIcons();
this.eventsMenuCreator.registerEditorMenus();
this.commandCreator.registerCommands();
this.icons.registerIcons();
this.ribbonIcons.registerRibbonIcons();
this.editorMenus.registerEditorMenus();
this.commands.registerCommands();

console.log(
"Plugin Loaded: Formatto\n(Error details are going to be displayed here.)"
Expand Down
5 changes: 3 additions & 2 deletions src/commands/commands.ts → src/obsidian/commands.ts
@@ -1,5 +1,6 @@
import { Command } from "obsidian";
import { getLocale, LOCALE_CATEGORY } from "src/lang/getLocale";

import { getLocale, LOCALE_CATEGORY } from "@src/lang/lang";

import FormattoPlugin from "../main";

Expand All @@ -16,7 +17,7 @@ export class FormattoCommands {
});
}

getCommandsArr(): Command[] {
private getCommandsArr(): Command[] {
return [
{
id: "formatto-logo",
Expand Down
@@ -1,6 +1,6 @@
import { getLocale, LOCALE_CATEGORY } from "src/lang/getLocale";
import { getLocale, LOCALE_CATEGORY } from "@src/lang/lang";

import FormattoPlugin from "../main";
import FormattoPlugin from "../../main";

export class FormattoEditorMenu {
private plugin: FormattoPlugin;
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { addIcon } from "obsidian";

import formattoLogo from "./img/formatto-logo.svg";

export class CustomIcons {
export class FormattoIcons {
private icons = [{ iconId: "formatto-logo", svg: formattoLogo }];

registerIcons = () => {
Expand Down
File renamed without changes
7 changes: 4 additions & 3 deletions src/etc/ribbonIcons.ts → src/obsidian/ribbonIcons.ts
@@ -1,8 +1,9 @@
import { MarkdownView, Notice } from "obsidian";
import { getLocale, LOCALE_CATEGORY } from "src/lang/getLocale";
import FormattoPlugin from "src/main";

export class RibbonIcons {
import { getLocale, LOCALE_CATEGORY } from "@src/lang/lang";
import FormattoPlugin from "@src/main";

export class FormattoRibbonIcons {
private plugin: FormattoPlugin;

constructor(plugin: FormattoPlugin) {
Expand Down
@@ -1,8 +1,9 @@
import { debounce, Notice, PluginSettingTab, Setting } from "obsidian";
import { getLocale, LOCALE_CATEGORY } from "src/lang/getLocale";

import { getLocale, LOCALE_CATEGORY } from "@src/lang/lang";

import type { App } from "obsidian";
import type FormattoPlugin from "../main";
import type FormattoPlugin from "../../main";

export class FormattoSettingTab extends PluginSettingTab {
private plugin: FormattoPlugin;
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions src/utils.ts → src/obsidian/utils.ts
@@ -1,8 +1,9 @@
import { Editor, Notice } from "obsidian";

import { format_document } from "../wasm/pkg/formatto_wasm";
import { getLocale, getWasmLocale, LOCALE_CATEGORY } from "./lang/getLocale";
import FormattoPlugin from "./main";
import { getLocale, getWasmLocale, LOCALE_CATEGORY } from "@src/lang/lang";

import { format_document } from "../../wasm/pkg/formatto_wasm";
import FormattoPlugin from "../main";

export class FormattoUtils {
private plugin: FormattoPlugin;
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Expand Up @@ -15,8 +15,8 @@
"lib": ["ES2022", "DOM"],
"baseUrl": "./",
"paths": {
"@events/*": ["./src/events/*"],
"@settings/*": ["./src/settings/*"]
"@src/*": ["src/*"],
"@components/*": ["src/obsidian/*"]
}
}
}

0 comments on commit 3a18aca

Please sign in to comment.