Apply JS formatter

This commit is contained in:
Aljaž Grilc 2024-02-07 09:08:53 +01:00
parent f3f37fff02
commit dd5a6ff85b

View File

@ -7,11 +7,7 @@ class BesEditor {
this.children = [] this.children = []
this.correctionPanel = document.getElementById('correction-panel') // TODO: use document.createElement('div') and insert it before edit element in DOM. this.correctionPanel = document.getElementById('correction-panel') // TODO: use document.createElement('div') and insert it before edit element in DOM.
this.proof(edit) this.proof(edit)
edit.addEventListener( edit.addEventListener('beforeinput', e => this.handleBeforeInput(e), false)
'beforeinput',
e => this.handleBeforeInput(e),
false
)
edit.addEventListener('click', e => this.handleClick(e)) edit.addEventListener('click', e => this.handleClick(e))
} }
@ -20,7 +16,7 @@ class BesEditor {
switch (el.nodeType) { switch (el.nodeType) {
case Node.TEXT_NODE: case Node.TEXT_NODE:
return [{ text: el.textContent, el: el, markup: false }] return [{ text: el.textContent, el: el, markup: false }]
case Node.ELEMENT_NODE: case Node.ELEMENT_NODE:
if (BesEditor.isBlockElement(el)) { if (BesEditor.isBlockElement(el)) {
// Block elements are grammar-proofed independently. // Block elements are grammar-proofed independently.
@ -60,7 +56,7 @@ class BesEditor {
let matches = [] let matches = []
responseData.matches.forEach(match => { responseData.matches.forEach(match => {
let range = document.createRange() let range = document.createRange()
// Locate start of the grammar mistake. // Locate start of the grammar mistake.
for ( for (
let idx = 0, startingOffset = 0; let idx = 0, startingOffset = 0;
@ -72,11 +68,14 @@ class BesEditor {
/*startingOffset <= match.offset &&*/ match.offset < /*startingOffset <= match.offset &&*/ match.offset <
startingOffset + data[idx].text.length startingOffset + data[idx].text.length
) { ) {
range.setStart(data[idx].el, match.offset - startingOffset) range.setStart(
data[idx].el,
match.offset - startingOffset
)
break break
} }
} }
// Locate end of the grammar mistake. // Locate end of the grammar mistake.
let endOffset = match.offset + match.length let endOffset = match.offset + match.length
for ( for (
@ -93,14 +92,14 @@ class BesEditor {
break break
} }
} }
matches.push({ matches.push({
range: range, range: range,
rects: this.addMistakeMarkup(range, match), rects: this.addMistakeMarkup(range, match),
match: match match: match
}) })
}) })
this.markProofed(el, matches) this.markProofed(el, matches)
}) })
.catch(error => { .catch(error => {
@ -123,7 +122,7 @@ class BesEditor {
}) })
return data return data
} }
default: default:
return [{ text: '<?' + el.nodeType + '>', el: el, markup: true }] return [{ text: '<?' + el.nodeType + '>', el: el, markup: true }]
} }
@ -231,7 +230,8 @@ class BesEditor {
// Returns first block parent element // Returns first block parent element
getBlockParent(el) { getBlockParent(el) {
for (; el && el !== this.el; el = el.parentNode) { for (; el && el !== this.el; el = el.parentNode) {
if (el.nodeType === Node.ELEMENT_NODE && BesEditor.isBlockElement(el)) return el if (el.nodeType === Node.ELEMENT_NODE && BesEditor.isBlockElement(el))
return el
} }
return el return el
} }
@ -277,7 +277,7 @@ class BesEditor {
} }
return false return false
} }
static isPointInRect(x, y, rect) { static isPointInRect(x, y, rect) {
return ( return (
x >= rect.x && x >= rect.x &&