Skip to content

Commit

Permalink
Merge pull request #2 from alephpiece/add-standalone-menu
Browse files Browse the repository at this point in the history
Add a standalone menu
  • Loading branch information
alephpiece authored Dec 20, 2023
2 parents 050b3ed + 346f2dc commit e10f472
Show file tree
Hide file tree
Showing 33 changed files with 611 additions and 88 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Customizable slash command list for [Obsidian](https://obsidian.md).

## How to install

### Community plugins

1. Open Obsidian settings and scroll to "Community plugins".
2. Turn off the restricted mode.
3. Browse community plugins, search `Slash Commander` and install it.
4. Enable this plugin.

### Using BRAT

1. Install this plugin using BRAT.
- Go to "Community plugins" and install "Obsidian42 - BRAT".
- Add https://github.com/alephpiece/obsidian-slash-commander to BRAT.
Expand All @@ -33,5 +42,9 @@ Customizable slash command list for [Obsidian](https://obsidian.md).

## Credits

- Idea & logic: [Obsidian Better Slash Command](https://github.com/SPiCaRiA/obsidian-better-slash-commands)
- UI design & data structures: based on [Obsidian Commander](https://github.com/phibr0/obsidian-commander)
- Idea & logic: [Better Slash Command](https://github.com/SPiCaRiA/obsidian-better-slash-commands)
- UI design & data structures: based on [Commander](https://github.com/phibr0/obsidian-commander)
- Standalone menu suggest:
- idea: [FelipeRearden](https://github.com/FelipeRearden)
- suggester: [Periodic Notes](https://github.com/liamcain/obsidian-periodic-notes) and [Admonitions](https://github.com/javalent/admonitions)
- positioning: [Highlightr](https://github.com/chetachiezikeuzor/Highlightr-Plugin) and [Typing Assistant](https://github.com/Jambo2018/notion-assistant-plugin)
3 changes: 2 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
"Command trigger conflicts with the 'Slash commands' plugin.": "Command trigger conflicts with the 'Slash commands' plugin.",
"Please pick another trigger or disable the above plugin, and then reload this setting tab to dismiss this warning.": "Please pick another trigger or disable the above plugin, and then reload this setting tab to dismiss this warning.",
"Only on new line": "Only on new line",
"Show slash commands only if the trigger is at the beginning of a line.": "Show slash commands only if the trigger is at the beginning of a line."
"Show slash commands only if the trigger is at the beginning of a line.": "Show slash commands only if the trigger is at the beginning of a line.",
"Open standalone menu": "Open standalone menu"
}
3 changes: 2 additions & 1 deletion locale/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
"Command trigger conflicts with the 'Slash commands' plugin.": "命令触发符和插件“斜杠命令”冲突。",
"Please pick another trigger or disable the above plugin, and then reload this setting tab to dismiss this warning.": "请更换命令触发符或关闭上述插件,随后重新加载该设置页面以消除警告信息。",
"Only on new line": "仅用于新行",
"Show slash commands only if the trigger is at the beginning of a line.": "仅当命令触发符位于行首才会触发斜杠命令。"
"Show slash commands only if the trigger is at the beginning of a line.": "仅当命令触发符位于行首才会触发斜杠命令。",
"Open standalone menu": "打开独立的选单。"
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "slash-commander",
"name": "Slash Commander",
"version": "0.2.2",
"version": "0.2.3",
"minAppVersion": "1.4.5",
"description": "Customize the slash command list, assign each command an icon.",
"author": "alephpiece",
Expand Down
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slash-commander",
"version": "0.2.2",
"version": "0.2.3",
"description": "Customizable slash commands for Obsidian.md",
"main": "main.js",
"scripts": {
Expand All @@ -16,6 +16,7 @@
"keywords": [],
"author": "alephpiece",
"devDependencies": {
"@popperjs/core": "^2.9.2",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@typescript-eslint/eslint-plugin": "^5.45.0",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Fragment, h } from "preact";
import t from "src/l10n";
import SlashCommanderPlugin from "src/main";
import { CommandIconPair } from "src/types";
import { getCommandFromId, ObsidianIcon, getCommandSourceName } from "src/util";
import MobileModifyModal from "../mobileModifyModal";
import ChangeableText from "./ChangeableText";
import { getCommandFromId, ObsidianIcon, getCommandSourceName } from "src/utils/util";
import MobileModifyModal from "../settings/mobileModifyModal";
import ChangeableText from "./changeableText";

interface CommandViewerProps {
interface CommandProps {
plugin: SlashCommanderPlugin;
pair: CommandIconPair;
handleRemove: () => void;
Expand All @@ -29,7 +29,7 @@ export default function CommandComponent({
handleRename,
handleModeChange,
sortable = true,
}: CommandViewerProps): h.JSX.Element {
}: CommandProps): h.JSX.Element {
const cmd = getCommandFromId(plugin, pair.id);
if (!cmd) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { createContext, Fragment, h } from "preact";
import SlashCommanderPlugin from "src/main";
import CommandComponent from "./commandComponent";
import CommandManager from "src/manager/commandManager";
import { chooseNewCommand, isModeActive, ObsidianIcon } from "src/util";
import { chooseNewCommand, isModeActive, ObsidianIcon } from "src/utils/util";
import { arrayMoveMutable } from "array-move";
import ChooseIconModal from "../chooseIconModal";
import ConfirmDeleteModal from "../confirmDeleteModal";
import ChooseIconModal from "../settings/chooseIconModal";
import ConfirmDeleteModal from "../settings/confirmDeleteModal";
import t from "src/l10n";
import { Platform } from "obsidian";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fragment, h } from "preact";
import t from "src/l10n";
import ConfirmDeleteModal from "../confirmDeleteModal";
import ConfirmDeleteModal from "../settings/confirmDeleteModal";

export function confirmDeleteComponent({
modal,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { h } from "preact";
import { useEffect } from "preact/hooks";
import t from "src/l10n";
import { ObsidianIcon } from "src/util";
import MobileModifyModal from "../mobileModifyModal";
import { ObsidianIcon } from "src/utils/util";
import MobileModifyModal from "../settings/mobileModifyModal";

export default function MobileModifyComponent({
modal: controller,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Fragment, h } from "preact";
import t from "src/l10n";
import { ObsidianIcon, buildQueryPattern, isTriggerInConflicts } from "src/util";
import SlashCommanderPlugin from "../../main";
import { ObsidianIcon, isTriggerInConflicts } from "src/utils/util";
import { buildQueryPattern } from "src/utils/search";
import SlashCommanderPlugin from "../main";
import CommandViewer from "./commandViewerComponent";
import {
ToggleComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fragment, h } from "preact";
import SlashCommanderPlugin from "src/main";
import { CommandIconPair } from "src/types";
import { getCommandFromId, getCommandSourceName, isCommandNameUnique, ObsidianIcon } from "src/util";
import { getCommandFromId, getCommandSourceName, isCommandNameUnique, ObsidianIcon } from "src/utils/util";

interface SuggestionProps {
plugin: SlashCommanderPlugin;
Expand Down Expand Up @@ -29,7 +29,7 @@ export default function SuggestionComponent({
"cmdr-suggest-item-icon"
}
/>
<div className="cmdr-suggest-item-name">
<div className="cmdr-suggest-content">
<div>
{pair.name}
{
Expand Down
49 changes: 42 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Plugin } from "obsidian";
import { MarkdownView, Plugin } from "obsidian";
import { DEFAULT_SETTINGS } from "./constants";
import t from "./l10n";
import { CommanderSettings } from "./types";
import CommanderSettingTab from "./ui/settingTab";
import SettingTabModal from "./ui/settingTabModal";
import { CommanderSettings, EnhancedEditor } from "./types";
import CommanderSettingTab from "./settings/settingTab";
import SettingTabModal from "./settings/settingTabModal";
import CommandManager from "./manager/commandManager";
import { SlashSuggester } from "./suggest";
import { buildQueryPattern } from "./util";
import { SlashSuggester } from "./suggesters/slashSuggest";
import { MenuSuggest } from "./suggesters/menuSuggest";
import { buildQueryPattern } from "./utils/search";

import "./styles/styles.scss";
import registerCustomIcons from "./ui/icons";
import registerCustomIcons from "./assets/icons";

export default class SlashCommanderPlugin extends Plugin {
public settings: CommanderSettings;
public manager: CommandManager;
public scrollArea?: Element | undefined;
public menuSuggest?: MenuSuggest;

public async onload(): Promise<void> {
await this.loadSettings();
Expand All @@ -30,11 +33,43 @@ export default class SlashCommanderPlugin extends Plugin {
callback: () => new SettingTabModal(this).open(),
});

this.addCommand({
name: t("Open standalone menu"),
id: "open-standalone-menu",
editorCallback: (editor: EnhancedEditor) => {
this.menuSuggest?.close();
this.menuSuggest = new MenuSuggest(this, editor, this.scrollArea);
this.menuSuggest.open();
},
});

this.registerEditorSuggest(new SlashSuggester(this));

this.registerDomEvent(document, "click", (evt: MouseEvent) => {
this.menuSuggest?.close();
});

// Get the scroller area
// Credits go to https://github.com/Jambo2018/notion-assistant-plugin
const renderPlugin = (): void => {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view) return;
this.scrollArea =
view.containerEl.querySelector(".cm-scroller") ?? undefined;
if (!this.scrollArea) return;
};

/**Ensure that the plugin can be loaded and used immediately after it is turned on */
renderPlugin();

this.registerEvent(
this.app.workspace.on("active-leaf-change", renderPlugin)
);
}

public onunload(): void {
document.head.querySelector("style#cmdr")?.remove();
this.menuSuggest?.close();
}

private async loadSettings(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/manager/commandManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DEFAULT_SETTINGS } from "src/constants";
import SlashCommanderPlugin from "src/main";
import { CommandIconPair } from "src/types";
import { isModeActive } from "src/util";
import { isModeActive } from "src/utils/util";

export default class CommandManager {
public pairs: CommandIconPair[];
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICON_LIST } from "./../constants";
import { ICON_LIST } from "../constants";
import { setIcon, FuzzySuggestModal, FuzzyMatch } from "obsidian";
import SlashCommanderPlugin from "src/main";
import t from "src/l10n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Modal } from "obsidian";
import { h, render, VNode } from "preact";
import t from "src/l10n";
import SlashCommanderPlugin from "src/main";
import { confirmDeleteComponent } from "./components/confirmDeleteComponent";
import { confirmDeleteComponent } from "../components/confirmDeleteComponent";

export default class ConfirmDeleteModal extends Modal {
private reactComponent: VNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { CommandIconPair } from "src/types";
import { Modal } from "obsidian";
import { h, render, VNode } from "preact";
import MobileModifyComponent from "./components/mobileModifyComponent";
import MobileModifyComponent from "../components/mobileModifyComponent";
import SlashCommanderPlugin from "src/main";

export default class MobileModifyModal extends Modal {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/settingTab.ts → src/settings/settingTab.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Platform, PluginSettingTab } from "obsidian";
import { h, render } from "preact";
import SlashCommanderPlugin from "../main";
import settingTabComponent from "./components/settingTabComponent";
import settingTabComponent from "../components/settingTabComponent";

export default class CommanderSettingTab extends PluginSettingTab {
private plugin: SlashCommanderPlugin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Modal, Platform } from "obsidian";
import { h, render } from "preact";
import SlashCommanderPlugin from "src/main";
import settingTabComponent from "./components/settingTabComponent";
import settingTabComponent from "../components/settingTabComponent";

export default class SettingTabModal extends Modal {
private plugin: SlashCommanderPlugin;
Expand Down
13 changes: 12 additions & 1 deletion src/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@
}
}

.cmdr-suggest-item-name {
.cmdr-suggest-content {
flex: 1 1 auto;
overflow: hidden;
text-overflow: ellipsis;
Expand All @@ -609,4 +609,15 @@
.cmdr-suggest-item-source {
font-style: italic;
color: dimgray;
}

.cmdr-standalone-menu {
overflow: scroll;
}

.cmdr-standalone-menu-item {
margin-left: 6px;
&:hover {
background-color: var(--background-modifier-hover);
}
}
Loading

0 comments on commit e10f472

Please sign in to comment.