From 933eba7dc3bdc979fefadd47388b20b8360e1d6b Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 28 Sep 2024 17:47:52 +0800 Subject: style: prettier --- src/MenuItem.mjs | 102 +++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'src/MenuItem.mjs') diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index 85ab1a2..2f9aff4 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs @@ -1,97 +1,97 @@ -import { createGeoLink } from './dumbymap' +import { createGeoLink } from "./dumbymap"; export function nextMap() { - const element = document.createElement('div') - element.className = 'menu-item' - element.innerHTML = 'Next Map (Tab)' - element.onclick = () => this.utils.focusNextMap() + const element = document.createElement("div"); + element.className = "menu-item"; + element.innerHTML = 'Next Map (Tab)'; + element.onclick = () => this.utils.focusNextMap(); - return element + return element; } export function nextBlock() { - const element = document.createElement('div') - element.className = 'menu-item' - element.innerHTML = 'Next Block (n)' - element.onclick = () => this.utils.focusNextBlock() + const element = document.createElement("div"); + element.className = "menu-item"; + element.innerHTML = 'Next Block (n)'; + element.onclick = () => this.utils.focusNextBlock(); - return element + return element; } export function nextLayout() { - const element = document.createElement('div') - element.className = 'menu-item' - element.innerHTML = 'Next Layout (x)' - element.onclick = () => this.utils.switchToNextLayout() + const element = document.createElement("div"); + element.className = "menu-item"; + element.innerHTML = 'Next Layout (x)'; + element.onclick = () => this.utils.switchToNextLayout(); - return element + return element; } export class GeoLink { - constructor({ range }) { - this.range = range + this.range = range; } createElement = () => { - const element = document.createElement('div') - element.className = 'menu-item' - element.innerText = "Add GeoLink" - element.onclick = this.addGeoLinkbyRange + const element = document.createElement("div"); + element.className = "menu-item"; + element.innerText = "Add GeoLink"; + element.onclick = this.addGeoLinkbyRange; - return element - } + return element; + }; addGeoLinkbyRange = () => { - const range = this.range - const content = range.toString() + const range = this.range; + const content = range.toString(); // FIXME Apply geolink only on matching sub-range - const match = content.match(/(^\D*[\d.]+)\D+([\d.]+)\D*$/) - if (!match) return false + const match = content.match(/(^\D*[\d.]+)\D+([\d.]+)\D*$/); + if (!match) return false; - const [x, y] = match.slice(1) - const anchor = document.createElement('a') - anchor.textContent = content + const [x, y] = match.slice(1); + const anchor = document.createElement("a"); + anchor.textContent = content; // FIXME apply WGS84 - anchor.href = `geo:${y},${x}?xy=${x},${y}` + anchor.href = `geo:${y},${x}?xy=${x},${y}`; if (createGeoLink(anchor)) { - range.deleteContents() - range.insertNode(anchor) + range.deleteContents(); + range.insertNode(anchor); } - } + }; } export class Suggestion { constructor({ text, replace }) { - this.text = text - this.replace = replace + this.text = text; + this.replace = replace; } createElement(codemirror) { - const option = document.createElement('div'); - if (this.text.startsWith('<')) { + const option = document.createElement("div"); + if (this.text.startsWith("<")) { option.innerHTML = this.text; } else { option.innerText = this.text; } - option.classList.add('container__suggestion'); + option.classList.add("container__suggestion"); option.onmouseover = () => { - Array.from(option.parentElement?.children ?? []) - .forEach(s => s.classList.remove('focus')) - option.classList.add('focus') - } + Array.from(option.parentElement?.children ?? []).forEach(s => + s.classList.remove("focus"), + ); + option.classList.add("focus"); + }; option.onmouseout = () => { - option.classList.remove('focus') - } + option.classList.remove("focus"); + }; option.onclick = () => { - const anchor = codemirror.getCursor() - codemirror.setSelection(anchor, { ...anchor, ch: 0 }) - codemirror.replaceSelection(this.replace) + const anchor = codemirror.getCursor(); + codemirror.setSelection(anchor, { ...anchor, ch: 0 }); + codemirror.replaceSelection(this.replace); codemirror.focus(); - const newAnchor = { ...anchor, ch: this.replace.length } + const newAnchor = { ...anchor, ch: this.replace.length }; codemirror.setCursor(newAnchor); }; - return option + return option; } } -- cgit v1.2.3-70-g09d2