Skip to content

Commit

Permalink
v0.4.0
Browse files Browse the repository at this point in the history
Fixed #14 Address review comments (Add RunJS plugin - Pull Request, issuecomment-1614281555)
  • Loading branch information
eoureo committed Jul 1, 2023
1 parent 80f192e commit 881d6f2
Show file tree
Hide file tree
Showing 15 changed files with 550 additions and 314 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "runjs",
"name": "RunJS",
"version": "0.3.0",
"version": "0.4.0",
"minAppVersion": "0.15.0",
"description": "RunJS is a plugin for running JavaScript code in Obsidian (https://obsidian.md).",
"description": "Run easily JavaScript codes for managing Obsidian and its notes.",
"author": "eoureo",
"authorUrl": "https://github.com/eoureo",
"fundingUrl": "https://buymeacoffee.com/eoureo",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "runjs",
"version": "0.3.0",
"description": "RunJS is a plugin for running JavaScript code in Obsidian (https://obsidian.md).",
"version": "0.4.0",
"description": "Run easily JavaScript codes for managing Obsidian and its notes.",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
12 changes: 8 additions & 4 deletions src/code_modal.ts → src/codelist_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { Code } from "./main";
import { LIST_ICON } from "./constants";

export class RunJSCodeModal extends SuggestModal<Code> {
export class RunJSCodeListModal extends SuggestModal<Code> {
codes: Code[];
onSubmit: (code: Code) => void;
plugin: Plugin;
Expand Down Expand Up @@ -68,9 +68,13 @@ export class RunJSCodeModal extends SuggestModal<Code> {
this.gotoUpperGroup.bind(this)
);

this.containerEl.addClass("runjs-code-modal");
const promptEl = this.containerEl.querySelector(".prompt");
promptEl?.insertBefore(this.titleEl, promptEl.firstChild);
this.containerEl.addClass("runjs-codelist-modal");

// const promptEl = this.containerEl.querySelector(".prompt");
// promptEl?.insertBefore(this.titleEl, promptEl.firstChild);
if (this.titleEl && this.titleEl.parentElement == null) {
this.modalEl?.insertBefore(this.titleEl, this.modalEl.firstChild);
}

if (this.promptInputContainerEl) this.promptInputContainerEl.dataset.parent = this.groupParent;
this.promptInputContainerEl?.addEventListener("click", (e) => {
Expand Down
62 changes: 31 additions & 31 deletions src/codelist_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LIST_ICON, RunJS_LISTVIEW_ICON } from "./constants";

export const RunJSCodeListViewType = "runjs-codelist-view";

export class RunJSListView extends ItemView {
export class RunJSCodeListView extends ItemView {
private readonly plugin: RunJSPlugin;
table: HTMLTableElement;
menuFilter: Menu;
Expand Down Expand Up @@ -52,7 +52,7 @@ export class RunJSListView extends ItemView {
// }

public onload() {
this.containerEl.classList.add("runjs-listview-container");
this.containerEl.classList.add("runjs-codelist-view-container");

const navHeader = createDiv({ cls: "nav-header" });
this.containerEl.insertBefore(navHeader, this.containerEl.firstChild);
Expand Down Expand Up @@ -103,7 +103,7 @@ export class RunJSListView extends ItemView {

// @ts-ignore
const menuFilterDom = this.menuFilter.dom;
menuFilterDom.classList.add("runjs-listview-menu");
menuFilterDom.classList.add("runjs-codelist-view-menu");

const filters = this.plugin.settings.listviewFilters;

Expand Down Expand Up @@ -131,7 +131,7 @@ export class RunJSListView extends ItemView {
.setTitle(option)
.setIcon(LIST_ICON[option])
.onClick(() => {
if (filters[group].contains(option)) {
if (filters[group]?.contains(option)) {
filters[group].remove(option);
if (
options.length > 1 &&
Expand All @@ -140,6 +140,7 @@ export class RunJSListView extends ItemView {
filters[group] = options.slice();
}
} else {
if (!(group in filters)) filters[group] = [];
filters[group].push(option);
}

Expand Down Expand Up @@ -187,11 +188,12 @@ export class RunJSListView extends ItemView {
const option = "favorite";
const ft_op = "ft-" + option;

if (filters[group].contains(option)) {
if (filters[group]?.contains(option)) {
filters[group].remove(option);
this.containerEl.classList.remove(ft_op);
menuFilterDom.classList.remove(ft_op);
} else {
if (!(group in filters)) filters[group] = [];
filters[group].push(option);
this.containerEl.classList.add(ft_op);
menuFilterDom.classList.add(ft_op);
Expand All @@ -215,7 +217,7 @@ export class RunJSListView extends ItemView {
this.menuOther = new Menu();
let menuItemAutoRefresh: MenuItem;
// @ts-ignore
this.menuOther.dom.classList.add("runjs-listview-menu");
this.menuOther.dom.classList.add("runjs-codelist-view-menu");
this.menuOther.addItem((item) => {
menuItemAutoRefresh = item;
item
Expand Down Expand Up @@ -516,14 +518,14 @@ export class RunJSListView extends ItemView {
openFileContextMenu(event: MouseEvent, code: Code, treeItem: HTMLDivElement) {
const menu = new Menu();
// @ts-ignore
menu.dom?.classList.add("runjs-listview-menu");
menu.dom?.classList.add("runjs-codelist-view-menu");

if (code.type == "script") {
menu.addItem((item) =>
item
.setTitle("Run code")
.setIcon("lucide-scroll")
.setSection("runjs-listview")
.setSection("runjs-codelist-view")
.onClick(() => {
this.plugin.runCode(code);
})
Expand All @@ -534,7 +536,7 @@ export class RunJSListView extends ItemView {
item
.setTitle("Toggle Favorite code")
.setIcon(LIST_ICON["favorite"])
.setSection("runjs-listview")
.setSection("runjs-codelist-view")
.onClick(() => {
treeItem.classList.toggle("favorite");
this.plugin.toggleFavoriteCode(code);
Expand All @@ -557,7 +559,7 @@ export class RunJSListView extends ItemView {
item
.setTitle("Open code file")
.setIcon("lucide-edit")
.setSection("runjs-listview")
.setSection("runjs-codelist-view")
.onClick(() => {
this.focusFile(
code,
Expand Down Expand Up @@ -606,7 +608,7 @@ export class RunJSListView extends ItemView {
})
}

private readonly focusFile = async (
focusFile = async (
code: Code,
shouldSplit = false
): Promise<void> => {
Expand All @@ -615,28 +617,26 @@ export class RunJSListView extends ItemView {
.find((f) => f.path === code.file);

if (targetFile) {
let leaf: WorkspaceLeaf = <WorkspaceLeaf>(
this.app.workspace.getMostRecentLeaf()
);

const createLeaf = shouldSplit || leaf.getViewState().pinned;
if (createLeaf) {
if (this.plugin.settings.listviewOpenType == "split")
leaf = this.app.workspace.getLeaf("split");
else if (this.plugin.settings.listviewOpenType == "window")
leaf = this.app.workspace.getLeaf("window");
else leaf = this.app.workspace.getLeaf("tab");
}
await leaf.openFile(targetFile);

if (code.form != "codeblock") return;
let leaf = this.app.workspace.getMostRecentLeaf();

if (leaf) {
const createLeaf = shouldSplit || leaf.getViewState().pinned;
if (createLeaf) {
if (this.plugin.settings.listviewOpenType == "split")
leaf = this.app.workspace.getLeaf("split");
else if (this.plugin.settings.listviewOpenType == "window")
leaf = this.app.workspace.getLeaf("window");
else leaf = this.app.workspace.getLeaf("tab");
}
await leaf.openFile(targetFile);

const viewState = leaf.getViewState();
viewState.state.mode = "source";
viewState.state.source = true;
await leaf.setViewState(viewState);
if (code.form != "codeblock") return;

sleep(50);
const viewState = leaf.getViewState();
viewState.state.mode = "source";
viewState.state.source = true;
await leaf.setViewState(viewState);
}

// @ts-ignore
const editor = this.app.workspace.getActiveViewOfType(MarkdownView)?.sourceMode.cmEditor;
Expand Down
15 changes: 4 additions & 11 deletions src/confirm_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,28 @@ export class ConfirmModal extends Modal {
const buttonDiv = contentEl.createDiv({cls: "modal-button-container"});

new ButtonComponent(buttonDiv)
.setButtonText("OK")
.setButtonText("Yes")
.setCta()
.onClick(() => {
this.callback(true);
this.close();
})
.setCta();

new ButtonComponent(buttonDiv).setButtonText("Cancel").onClick(() => {
new ButtonComponent(buttonDiv).setButtonText("No").onClick(() => {
this.callback(false);
this.close();
});
}

onClose() {
this.callback(false);
const { contentEl } = this;
contentEl.empty();
}
}

export async function openConfirmModal (app: App, title: string | null, message: string, callback?: ConfirmCallback) {
let return_value;

const promise = new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
new ConfirmModal(
app,
title,
Expand All @@ -62,12 +59,9 @@ export async function openConfirmModal (app: App, title: string | null, message:
})
).open();
});

await promise.then(value => {return_value = value});
return return_value;
}

export default class ConfirmDeleteModal extends Modal {
export class ConfirmDeleteModal extends Modal {
title: string | null;
message: string;
callback: ConfirmCallback;
Expand Down Expand Up @@ -125,4 +119,3 @@ export function openConfirmDeleteModal (app: App, title: string, message: string
callback
).open();
}

Loading

0 comments on commit 881d6f2

Please sign in to comment.