Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
benjypng committed Feb 6, 2022
1 parent 1eea226 commit f72b356
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "darwis-mathlive-plugin",
"version": "1.0.5",
"version": "1.0.6",
"description": "",
"main": "dist/index.html",
"targets": {
Expand Down
40 changes: 16 additions & 24 deletions src/mathliveCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,30 @@ export const renderMathLive = (
connectedCallback() {
this.render();

window.setTimeout(() => {
top?.document
.getElementById('container')
.addEventListener('mousedown', async (e) => {
e.stopPropagation();
e.preventDefault();
await logseq.Editor.restoreEditingCursor();
});
window.setTimeout(async () => {
const formulaDiv = top?.document.getElementById(
`formula-${uniqueIdentifier}`
);

top?.document
.getElementById('formula')
.addEventListener('input', async (ev) => {
await logseq.Editor.upsertBlockProperty(
uuid,
'output',
//@ts-expect-error
ev.target.value
);
});
formulaDiv.addEventListener('input', async (ev) => {
await logseq.Editor.upsertBlockProperty(
uuid,
'output',
//@ts-expect-error
ev.target.value
);
});

top?.document
.getElementById('formula')
.addEventListener('change', async () => {
await logseq.Editor.restoreEditingCursor();
});
formulaDiv.addEventListener('change', async () => {
await logseq.Editor.restoreEditingCursor();
});
}, 500);
}

async render() {
const output = await logseq.Editor.getBlockProperty(uuid, 'output');

this.innerHTML = `<div id="container"><math-field tabindex="-1" id="formula" virtual-keyboard-mode=manual style="
this.innerHTML = `<div id="container-${uniqueIdentifier}"><math-field tabindex="1" id="formula-${uniqueIdentifier}" virtual-keyboard-mode=manual style="
font-size: 22px;
border-radius: 8px;
padding: 0 0 20px 20px;
Expand Down

0 comments on commit f72b356

Please sign in to comment.