implement modular command lists

This commit is contained in:
fuwaa 2022-08-23 11:40:41 +08:00
parent f9ca7dc5a1
commit 313cdcda85
No known key found for this signature in database
GPG key ID: 7CE0BF0D3175E2DC
7 changed files with 602 additions and 12 deletions

View file

@ -85,10 +85,4 @@ export default [
command: "application:quick-note", command: "application:quick-note",
shortcut: [""], shortcut: [""],
}, },
{
name: "!Toggle Strong/Bold",
category: "Core",
command: "core:strong",
shortcut: [""],
},
]; ];

View file

@ -1,3 +1,366 @@
"use babel"; "use babel";
export default []; export default [
{
name: "!Copy",
category: "Core",
command: "core:copy",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Copy Image",
category: "Core",
command: "core:copy-image",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Copy Note Link",
category: "Core",
command: "core:copy-note-link",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Cut",
category: "Core",
command: "core:cut",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Delete Note",
category: "Core",
command: "core:delete-note",
selector: "body",
shortcut: [""],
},
{
name: "!Delete Notebook",
category: "Core",
command: "core:delete-notebook",
state: "disabled",
shortcut: [""],
},
{
name: "!Delete Tag",
category: "Core",
command: "core:delete-tag",
state: "disabled",
shortcut: [""],
},
{
name: "!Duplicate Note",
category: "Core",
command: "core:duplicate-note",
selector: "body",
shortcut: [""],
},
{
name: "!Empty Trash",
category: "Core",
command: "core:empty-trash",
selector: "body",
shortcut: [""],
},
{
name: "!Filter notes",
category: "Core",
command: "core:filter-notes",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Filter by tag",
category: "Core",
command: "core:filter-by-tag",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Find",
category: "Core",
command: "core:find",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Clear search bar",
category: "Core",
command: "core:find-clear",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Find (Global)",
category: "Core",
command: "core:find-global",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Focus next",
category: "Core",
command: "core:focus-next",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Focus note list bar",
category: "Core",
command: "core:focus-note-list-bar",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Focus previous",
category: "Core",
command: "core:focus-previous",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Move notebook",
category: "Core",
command: "core:move-notebook",
state: "disabled",
selector: "body",
shortcut: [""],
},
{
name: "!Move to notebook",
category: "Core",
command: "core:move-to-notebook",
selector: "body",
shortcut: [""],
},
{
name: "!Navigate back",
category: "Core",
command: "core:navigate-back",
selector: "body",
shortcut: [""],
},
{
name: "!Navigate forward",
category: "Core",
command: "core:navigate-forward",
selector: "body",
shortcut: [""],
},
{
name: "!New Note",
category: "Core",
command: "core:new-note",
selector: "body",
shortcut: [""],
},
{
name: "!New Notebook",
category: "Core",
command: "core:new-notebook",
selector: "body",
shortcut: [""],
},
{
name: "!Show all notes",
category: "Core",
command: "core:note-list-show-all-notes",
selector: "body",
shortcut: [""],
},
{
name: "!Show all notes in specified notebook",
category: "Core",
command: "core:note-list-show-notes-in-book",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Show all notes by tag",
category: "Core",
command: "core:notes-list-show-notes-with-tag",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Show all notes with status",
category: "Core",
command: "core:note-list-show-notes-with-status",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Show notes in book of editing note",
category: "Core",
command: "core:note-list-show-notes-in-book-of-editing-note",
selector: "body",
shortcut: [""],
},
{
name: "!Open first note",
category: "Core",
command: "core:open-first-note",
selector: "body",
shortcut: [""],
},
{
name: "!Open next note",
category: "Core",
command: "core:open-next-note",
selector: "body",
shortcut: [""],
},
{
name: "!Close note",
category: "Core",
command: "core:close-note",
selector: "body",
shortcut: [""],
},
{
name: "!Open note",
category: "Core",
command: "core:open-note",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Open note in separate window",
category: "Core",
command: "core:open-note-in-separate-window",
selector: "body",
shortcut: [""],
},
{
name: "!Open previous note",
category: "Core",
command: "core:open-prev-note",
selector: "body",
shortcut: [""],
},
{
name: "!Open tag settings",
category: "Core",
command: "core:open-tag-settings",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Paste",
category: "Core",
command: "core:paste",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Redo",
category: "Core",
command: "core:redo",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: "!Rename Notebook",
category: "Core",
command: "core:rename-notebook",
selector: "body",
state: "disabled",
shortcut: [""],
},
{
name: "!Save Image",
category: "Core",
command: "core:save-image",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Save Note",
category: "Core",
command: "core:save-note",
selector: "body",
shortcut: [""],
},
{
name: "!Select all",
category: "Core",
command: "core:select-all",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Search notes",
category: "Core",
command: "core:search-notes",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Share note",
category: "Core",
command: "core:share-note",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Show note revisions",
category: "Core",
command: "core:show-note-revisions",
selector: "body",
state: "inprogress",
shortcut: [""],
},
{
name: "!Focus sidebar",
category: "Core",
command: "core:sidebar-focus",
selector: "body",
state: "error",
shortcut: [""],
},
{
name: "!Select next item on sidebar",
category: "Core",
command: "core:sidebar-select-next-item",
selector: "body",
shortcut: [""],
},
{
name: "!Select previous item on sidebar",
category: "Core",
command: "core:sidebar-select-prev-item",
selector: "body",
shortcut: [""],
},
{
name: "!Undo",
category: "Core",
command: "core:undo",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
];

3
lib/commands/editor.js Normal file
View file

@ -0,0 +1,3 @@
"use babel";
export default [];

144
lib/commands/formatting.js Normal file
View file

@ -0,0 +1,144 @@
"use babel";
export default [
{
name: ".Emphasize Text",
category: "Format",
command: "core:emphasize",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Indent",
category: "Format",
command: "core:indent",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Insert code block",
category: "Format",
command: "core:insert-code-block",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Insert horizontal rule",
category: "Format",
command: "core:insert-horizontal-rule",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Insert link",
category: "Format",
command: "core:insert-link",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Indent",
category: "Format",
command: "core:indent",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Insert code block",
category: "Format",
command: "core:insert-code-block",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Strikethrough",
category: "Format",
command: "core:strikethrough",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Embolden",
category: "Format",
command: "core:strong",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle blockquote",
category: "Format",
command: "core:toggle-blockquote",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle bulleted list",
category: "Format",
command: "core:toggle-bulleted-list",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle heading 1",
category: "Format",
command: "core:toggle-heading-1",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle heading 2",
category: "Format",
command: "core:toggle-heading-2",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle heading 3",
category: "Format",
command: "core:toggle-heading-3",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle-heading-4",
category: "Format",
command: "core:toggle-heading-4",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Make header bigger",
category: "Format",
command: "core:toggle-heading-bigger",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Make header smaller",
category: "Format",
command: "core:toggle-heading-smaller",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle numbered list",
category: "Format",
command: "core:toggle-numbered-list",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Toggle task list",
category: "Format",
command: "core:toggle-task-list",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
{
name: ".Unindent",
category: "Format",
command: "core:unindent",
selector: ".mde-cm-wrapper",
shortcut: [""],
},
];

View file

@ -0,0 +1,44 @@
"use babel";
export default [
{
name: "!Unselect items",
category: "Tags Bar",
command: "core:note-tags-bar-item-list-unselect",
selector: ".note-tags-bar-item-list",
state: "inprogress",
shortcut: [""],
},
{
name: "!Select previous item",
category: "Tags Bar",
command: "core:note-tags-bar-item-list-select-prev",
selector: ".note-tags-bar-item-list",
state: "inprogress",
shortcut: [""],
},
{
name: "!Select next item",
category: "Tags Bar",
command: "core:note-tags-bar-item-list-select-next",
selector: ".note-tags-bar-item-list",
state: "inprogress",
shortcut: [""],
},
{
name: "!Remove selected item and select previous item",
category: "Tags Bar",
command: "core:note-tags-bar-item-list-select-remove-item-before",
selector: ".note-tags-bar-item-list",
state: "inprogress",
shortcut: [""],
},
{
name: "!Remove selected item",
category: "Tags Bar",
command: "core:note-tags-bar-item-list-select-remove-item",
selector: ".note-tags-bar-item-list",
state: "inprogress",
shortcut: [""],
},
];

View file

@ -4,20 +4,42 @@ import React, { useEffect, useCallback, useLayoutEffect } from "react";
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
export default Option = (props) => { export default Option = (props) => {
let { name, category, command, shortcut, modal, idx } = props; let { name, category, command, shortcut, modal, idx, selector, state, args } =
props;
function execute() { function execute() {
ipcRenderer.send("command", command, {});
modal.close(); modal.close();
if (category === "Application") {
ipcRenderer.send("command", command, {});
}
if (category === "Core") {
if (selector === "body") {
inkdrop.commands.dispatch(document.body, command);
} else {
inkdrop.commands.dispatch(document.querySelector(selector), command);
}
}
// hide modal after executing // hide modal after executing
} }
const status = {
color:
state === "error"
? "#b86a85"
: state === "inprogress"
? "#b7b86a"
: state === "disabled"
? "var(--disabled-text-color)"
: null,
};
return ( return (
<a className="option flex-row" onClick={execute} href="#"> <a className="option flex-row" onClick={execute} href="#">
<p className="nomargin"> <p className="nomargin" style={status}>
{category} {category}
{category != "" ? ": " : ""} {category != "" ? ": " : ""}
{name.replace(/!/g, "").replace(/>/g, "")} {name.replace(/!/g, "").replace(/>/g, "").replace(/\./g, "")}
</p> </p>
<p className="nomargin"> <p className="nomargin">
{idx === 0 ? ( {idx === 0 ? (
@ -25,6 +47,21 @@ export default Option = (props) => {
<em>top result</em> <em>top result</em>
</span> </span>
) : null}{" "} ) : null}{" "}
{state === "error" ? (
<span className="nomargin topresult">
<em>not working / buggy</em>
</span>
) : null}{" "}
{state === "inprogress" ? (
<span className="nomargin topresult">
<em>untested / unimplemented</em>
</span>
) : null}{" "}
{state === "disabled" ? (
<span className="nomargin topresult">
<em>private command </em>
</span>
) : null}{" "}
{shortcut.map((key, index) => { {shortcut.map((key, index) => {
if (key == "") return null; if (key == "") return null;
else else

View file

@ -2,11 +2,16 @@
import React, { useEffect, useCallback, useRef, useLayoutEffect } from "react"; import React, { useEffect, useCallback, useRef, useLayoutEffect } from "react";
import Option from "./command.js"; import Option from "./command.js";
import Commands from "../commands/application.js"; import Application from "../commands/application.js";
import Core from "../commands/core.js";
import NoteTags from "../commands/notetagsbar.js";
import Formatting from "../commands/formatting.js";
import { logger, useModal } from "inkdrop"; import { logger, useModal } from "inkdrop";
import useArrowKeyNavigation from "../navigation/hook.js"; import useArrowKeyNavigation from "../navigation/hook.js";
const CommandPalette = (props) => { const CommandPalette = (props) => {
const Commands = [...Formatting, ...Application, ...Core, ...NoteTags];
const modal = useModal(); const modal = useModal();
const { Dialog } = inkdrop.components.classes; const { Dialog } = inkdrop.components.classes;