Skip to content

Commit

Permalink
Merge pull request #111 from obgnail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
obgnail authored Aug 23, 2023
2 parents 9be0ec9 + 369b540 commit 9413e9f
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 91 deletions.
59 changes: 29 additions & 30 deletions plugin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class commanderPlugin extends global._basePlugin {
style = () => {
const textID = "plugin-commander-style"
const text = `
#typora-commander {
#plugin-commander {
position: fixed;
top: 30%;
left: 55%;
Expand All @@ -26,18 +26,18 @@ class commanderPlugin extends global._basePlugin {
transform: translate3d(0, 0, 0)
}
.mac-seamless-mode #typora-commander {
.mac-seamless-mode #plugin-commander {
top: 30px
}
#typora-commander-form {
#plugin-commander-form {
display: flex;
align-items: center;
font-size: 14px;
line-height: 25px;
}
#typora-commander-form select, input {
#plugin-commander-form select, input {
border: 1px solid #ddd;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
border-radius: 2px;
Expand All @@ -46,22 +46,22 @@ class commanderPlugin extends global._basePlugin {
margin-bottom: 1px;
}
#typora-commander-form input {
#plugin-commander-form input {
width: 60%;
margin-left: 0;
margin-right: 2.5px;
padding-left: 5px;
padding-right: 24px;
}
#typora-commander-form select {
#plugin-commander-form select {
width: 20%;
margin-left: 2.5px;
margin-right: 0;
padding: 1px 2px;
}
#typora-commander-form .typora-commander-commit {
#plugin-commander-form .plugin-commander-commit {
position: absolute;
padding: 1px;
left: 335px;
Expand All @@ -70,7 +70,7 @@ class commanderPlugin extends global._basePlugin {
display: none;
}
.typora-commander-output {
.plugin-commander-output {
margin-top: 0;
cursor: default;
max-height: 340px;
Expand All @@ -79,18 +79,18 @@ class commanderPlugin extends global._basePlugin {
display:none;
}
.typora-commander-output pre {
.plugin-commander-output pre {
display: inline-block;
font-size: 13px;
line-height: 1.1;
margin: 10px 10px 5px 5px;
}
.typora-commander-output pre.error {
.plugin-commander-output pre.error {
color: red;
}
#typora-commander-form input:focus, pre:focus {
#plugin-commander-form input:focus, pre:focus {
outline: 0
}
`;
Expand All @@ -103,29 +103,28 @@ class commanderPlugin extends global._basePlugin {
<option value="${this.SHELL.GIT_BASH}">git bash</option>
<option value="${this.SHELL.WSL}">wsl</option>`;
const builtin = this.config.BUILTIN.map(ele => `<option shell="${ele.shell}" value='${ele.cmd}'>${ele.name}</option>`).join("");
const builtinSelect = !this.config.USE_BUILTIN ? "" : `<select class="typora-commander-builtin">${builtin}</select>`;
const builtinSelect = !this.config.USE_BUILTIN ? "" : `<select class="plugin-commander-builtin">${builtin}</select>`;

const div = `
<div id="typora-commander-form">
<div id="plugin-commander-form">
<input type="text" class="input" placeholder="Typora commander" autocorrect="off" spellcheck="false"
autocapitalize="off" data-lg="Front" title="提供如下环境变量:\n$f 当前文件路径\n$d 当前文件所属目录\n$m 当前挂载目录">
<i class="ion-ios7-play typora-commander-commit" ty-hint="执行命令"></i>
<select class="typora-commander-shell"><option value="${this.SHELL.CMD_BASH}">cmd/bash</option>${windowOption}</select>
<i class="ion-ios7-play plugin-commander-commit" ty-hint="执行命令"></i>
<select class="plugin-commander-shell"><option value="${this.SHELL.CMD_BASH}">cmd/bash</option>${windowOption}</select>
${builtinSelect}
</div>
<div class="typora-commander-output"><pre tabindex="0"></pre></div>
<div class="plugin-commander-output"><pre tabindex="0"></pre></div>
`
const modal = document.createElement("div");
modal.id = 'typora-commander';
modal.id = 'plugin-commander';
modal.style.display = "none";
modal.innerHTML = div;
const searchPanel = document.getElementById("md-searchpanel");
searchPanel.parentNode.insertBefore(modal, searchPanel.nextSibling);
this.utils.insertDiv(modal);

if (!this.config.USE_BUILTIN) {
document.getElementById('typora-commander').style.width = "500px";
document.querySelector("#typora-commander-form input").style.width = "80%";
document.querySelector("#typora-commander-form .typora-commander-commit").style.left = "375px";
document.getElementById('plugin-commander').style.width = "500px";
document.querySelector("#plugin-commander-form input").style.width = "80%";
document.querySelector("#plugin-commander-form .plugin-commander-commit").style.left = "375px";
}
}

Expand All @@ -138,13 +137,13 @@ class commanderPlugin extends global._basePlugin {

init = () => {
this.modal = {
modal: document.getElementById('typora-commander'),
input: document.querySelector("#typora-commander-form input"),
shellSelect: document.querySelector("#typora-commander-form .typora-commander-shell"),
builtinSelect: document.querySelector("#typora-commander-form .typora-commander-builtin"),
commit: document.querySelector("#typora-commander-form .typora-commander-commit"),
output: document.querySelector(".typora-commander-output"),
pre: document.querySelector(".typora-commander-output pre"),
modal: document.getElementById('plugin-commander'),
input: document.querySelector("#plugin-commander-form input"),
shellSelect: document.querySelector("#plugin-commander-form .plugin-commander-shell"),
builtinSelect: document.querySelector("#plugin-commander-form .plugin-commander-builtin"),
commit: document.querySelector("#plugin-commander-form .plugin-commander-commit"),
output: document.querySelector(".plugin-commander-output"),
pre: document.querySelector(".plugin-commander-output pre"),
}

this.arg_value_prefix = "call_builtin-";
Expand Down Expand Up @@ -197,7 +196,7 @@ class commanderPlugin extends global._basePlugin {
this.modal.modal.style.display = "none";
break
case "Tab":
const targetClass = this.config.USE_BUILTIN ? ".typora-commander-builtin" : ".typora-commander-shell";
const targetClass = this.config.USE_BUILTIN ? ".plugin-commander-builtin" : ".plugin-commander-shell";
const target = ev.target.closest(targetClass);
if (target) {
ev.stopPropagation();
Expand Down
8 changes: 4 additions & 4 deletions plugin/custom/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CustomPlugin extends global._basePlugin {
beforeProcess = () => {
this.custom = {};
this.modalHelper = new modalHelper(this.custom);
this.modalHelper = new modalHelper(this.custom, this.utils);
this.hotkeyHelper = new hotkeyHelper(this.custom);
this.dynamicCallHelper = new dynamicCallHelper(this.custom);
this.loadPluginHelper = new loadPluginHelper(this);
Expand Down Expand Up @@ -132,8 +132,9 @@ class hotkeyHelper {
}

class modalHelper {
constructor(custom) {
constructor(custom, utils) {
this.custom = custom;
this.utils = utils;
}

style = () => {
Expand Down Expand Up @@ -172,8 +173,7 @@ class modalHelper {
modal.id = "plugin-custom-modal";
modal.classList.add("modal-dialog");
modal.innerHTML = modal_content;
const quickOpenNode = document.getElementById("typora-quick-open");
quickOpenNode.parentNode.insertBefore(modal, quickOpenNode.nextSibling);
this.utils.insertDiv(modal);
}

process = () => {
Expand Down
5 changes: 3 additions & 2 deletions plugin/datatables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class datatablesPlugin extends global._basePlugin {
}

html = () => {
const jsFilepath = this.utils.joinPath("./plugin/datatables/resource/datatables.min.js");
$.getScript(`file:///${jsFilepath}`).then(() => console.log("datatables.min.js has inserted"));
this.utils.insertScript("./plugin/datatables/resource/datatables.min.js", () => {
console.log("datatables.min.js has inserted")
})
}

init = () => {
Expand Down
10 changes: 10 additions & 0 deletions plugin/global/core/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class utils {
document.getElementsByTagName('head')[0].appendChild(link);
}

static insertDiv = div => {
const quickOpenNode = document.getElementById("typora-quick-open");
quickOpenNode.parentNode.insertBefore(div, quickOpenNode.nextSibling);
}

static insertScript = (filepath, then) => {
const jsFilepath = this.joinPath(filepath);
$.getScript(`file:///${jsFilepath}`).then(then);
}

static metaKeyPressed = ev => File.isMac ? ev.metaKey : ev.ctrlKey
static shiftKeyPressed = ev => !!ev.shiftKey
static altKeyPressed = ev => !!ev.altKey
Expand Down
2 changes: 1 addition & 1 deletion plugin/go_top.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class goTopPlugin extends global._basePlugin {
const i = document.createElement("i");
i.classList.add("ion-arrow-up-c");
goTop.appendChild(i);
document.querySelector("body").appendChild(goTop);
this.utils.insertDiv(goTop);
}

init = () => {
Expand Down
10 changes: 5 additions & 5 deletions plugin/mermaid_replace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class mermaidReplacePlugin extends global._basePlugin {
this.utils.loopDetector(
() => window.editor && window.editor.diagrams && window.mermaidAPI,
() => {
const filepath = this.utils.joinPath("./plugin/mermaid_replace/mermaid.min.js");
$.getScript(`file:///${filepath}`).then(() => {
window.mermaidAPI = mermaid.mermaidAPI;
window.editor.diagrams.refreshDiagram(editor);
});
this.utils.insertScript("./plugin/mermaid_replace/mermaid.min.js", (() => {
window.mermaidAPI = mermaid.mermaidAPI;
window.editor.diagrams.refreshDiagram(editor);
})
)
}
);
}
Expand Down
11 changes: 5 additions & 6 deletions plugin/multi_highlighter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ class multiHighlighterPlugin extends global._basePlugin {
<span class="run-highlight ion-ios7-play" ty-hint="运行"></span>
</div>
<div id="plugin-multi-highlighter-result" style="display: none"></div>`
const searchModal = document.createElement("div");
searchModal.id = 'plugin-multi-highlighter';
searchModal.style.display = "none";
searchModal.innerHTML = div;
const quickOpenNode = document.getElementById("typora-quick-open");
quickOpenNode.parentNode.insertBefore(searchModal, quickOpenNode.nextSibling);
const modal = document.createElement("div");
modal.id = 'plugin-multi-highlighter';
modal.style.display = "none";
modal.innerHTML = div;
this.utils.insertDiv(modal);
}

hotkey = () => {
Expand Down
2 changes: 1 addition & 1 deletion plugin/outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class outlinePlugin extends global._basePlugin {
${all_button}
</div>
`
document.querySelector("header").appendChild(modal);
this.utils.insertDiv(modal);
}

init = () => {
Expand Down
Loading

0 comments on commit 9413e9f

Please sign in to comment.