Skip to content

Commit

Permalink
chore: fix some issues just introduced when fixing TypeScript issues
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Dec 8, 2023
1 parent e53a620 commit 5c6ea84
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/controls/contextmenu/ContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
const combo = keyComboFromEvent(event)
const direction: 'Up' | 'Down' | 'Left' | 'Right' | undefined = directionByCombo[combo]
if (direction && event.currentTarget) {
if (direction && event.target) {
event.preventDefault()
const buttons: HTMLButtonElement[] = Array.from(
refContextMenu.querySelectorAll('button:not([disabled])')
)
const nearest = findNearestElement<HTMLButtonElement>({
allElements: buttons,
currentElement: event.currentTarget as unknown as HTMLButtonElement,
currentElement: event.target as unknown as HTMLButtonElement,
direction,
hasPrio: (element: HTMLButtonElement) => {
return element.getAttribute('data-type') !== 'jse-open-dropdown'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
export let onContextMenu: OnContextMenu
function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
let buttonElem: Element | null = event.currentTarget
let buttonElem: Element | null = event.target as HTMLButtonElement
while (buttonElem && buttonElem.nodeName !== 'BUTTON') {
buttonElem = buttonElem.parentNode as Element
}
Expand All @@ -39,7 +39,7 @@
class="jse-context-menu-pointer"
class:jse-selected={selected}
title={CONTEXT_MENU_EXPLANATION}
on:click={(event) => handleClick(event)}
on:click={handleClick}
>
<Icon data={faCaretDown} />
</button>
Expand Down
27 changes: 12 additions & 15 deletions src/lib/components/modes/treemode/JSONNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@
function handleMouseDown(event: MouseEvent & { currentTarget: EventTarget & HTMLDivElement }) {
// check if the mouse down is not happening in the key or value input fields or on a button
if (
event.target &&
(isContentEditableDiv(event.currentTarget) ||
(event.which === 1 && isChildOfNodeName(event.currentTarget, 'BUTTON'))) // left mouse on a button
(isContentEditableDiv(event.target as HTMLElement) ||
(event.which === 1 && isChildOfNodeName(event.target as Element, 'BUTTON'))) // left mouse on a button
) {
return
}
Expand All @@ -263,7 +262,7 @@
document.addEventListener('mousemove', handleMouseMoveGlobal, true)
document.addEventListener('mouseup', handleMouseUpGlobal)
const anchorType = getSelectionTypeFromTarget(event.currentTarget)
const anchorType = getSelectionTypeFromTarget(event.target as Element)
const json = context.getJson()
const documentState = context.getDocumentState()
Expand Down Expand Up @@ -297,7 +296,7 @@
}
} else {
if (anchorType === SelectionType.multi) {
if (root && event.currentTarget.hasAttribute('data-path')) {
if (root && (event.target as Element).hasAttribute('data-path')) {
const lastCaretPosition = last(
getVisibleCaretPositions(value, documentState)
) as CaretPosition
Expand Down Expand Up @@ -326,7 +325,7 @@
}
}
const selectionType = getSelectionTypeFromTarget(event.currentTarget)
const selectionType = getSelectionTypeFromTarget(event.target as Element)
if (
!isEqual(path, singleton.selectionFocus) ||
Expand Down Expand Up @@ -419,7 +418,7 @@
})
dragging = {
initialTarget: event.currentTarget,
initialTarget: event.target as Element,
initialClientY: event.clientY,
initialContentTop: findContentTop(),
selectionStartIndex,
Expand Down Expand Up @@ -487,9 +486,9 @@
} else {
// the user did click inside the selection and no contents have been dragged,
// select the clicked item
if (event.currentTarget === dragging.initialTarget && !dragging.didMoveItems) {
const selectionType = getSelectionTypeFromTarget(event.currentTarget as Element)
const path = getDataPathFromTarget(event.currentTarget as Element)
if (event.target === dragging.initialTarget && !dragging.didMoveItems) {
const selectionType = getSelectionTypeFromTarget(event.target as Element)
const path = getDataPathFromTarget(event.target as Element)
if (path) {
context.onSelect(fromSelectionType(json, selectionType, path))
}
Expand Down Expand Up @@ -536,8 +535,6 @@
const startIndex = parseInt(last(startPath) as string, 10)
const endIndex = parseInt(last(endPath) as string, 10)
console.log('TEST', { startPath, endPath, startIndex, endIndex })
// find the section where the selection is
// if the selection is spread over multiple visible sections,
// we will not return any items, so dragging will not work there.
Expand Down Expand Up @@ -567,14 +564,14 @@
event.stopPropagation()
if (isChildOfAttribute(event.currentTarget, 'data-type', 'selectable-value')) {
if (isChildOfAttribute(event.target as Element, 'data-type', 'selectable-value')) {
hover = HOVER_COLLECTION
} else if (
isChildOfAttribute(event.currentTarget, 'data-type', 'insert-selection-area-inside')
isChildOfAttribute(event.target as Element, 'data-type', 'insert-selection-area-inside')
) {
hover = HOVER_INSERT_INSIDE
} else if (
isChildOfAttribute(event.currentTarget, 'data-type', 'insert-selection-area-after')
isChildOfAttribute(event.target as Element, 'data-type', 'insert-selection-area-after')
) {
hover = HOVER_INSERT_AFTER
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/modes/treemode/TreeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@
}
openContextMenu({
anchor: findParentWithNodeName(event.currentTarget, 'BUTTON'),
anchor: findParentWithNodeName(event.target, 'BUTTON'),
offsetTop: 0,
width: CONTEXT_MENU_WIDTH,
height: CONTEXT_MENU_HEIGHT,
Expand Down Expand Up @@ -1988,7 +1988,7 @@
function handleWindowMouseDown(event: MouseEvent & { currentTarget: EventTarget & Window }) {
const outsideEditor = !isChildOf(
event.currentTarget as Element,
event.target as Element,
(element) => element === refJsonEditor
)
if (outsideEditor) {
Expand Down

0 comments on commit 5c6ea84

Please sign in to comment.