Skip to content

Commit

Permalink
chore: minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sorax committed Jul 30, 2024
1 parent 6241afe commit 9e7632f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
25 changes: 2 additions & 23 deletions assets/js/hooks/events/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,10 @@ import {
focusItem,
getItemByNode,
moveItem,
setItemDirty,
setItemParent,
setItemPrev,
} from "../item";
import { getNodeByEvent, getNodeByItem } from "../node";

export function focusin(event: FocusEvent) {
const { uuid } = getNodeByEvent(event);

this.pushEvent("set_focus", uuid);
}

export function focusout(event: FocusEvent) {
const { uuid } = getNodeByEvent(event);

this.pushEvent("remove_focus", uuid);
}

export function input(event: Event) {
const node = getNodeByEvent(event);
const item = getItemByNode(node);
item && setItemDirty(item, true);

this.pushEvent("update_node_content", node);
}
export function keydown(event: KeyboardEvent) {
const container: HTMLDivElement = this.el.querySelector(".children");

Expand Down Expand Up @@ -193,7 +172,7 @@ function moveCursorDown(event: KeyboardEvent, outerThis: any) {
function moveNodeUp(
event: KeyboardEvent,
container: HTMLDivElement,
outerThis: any,
outerThis: any
) {
event.preventDefault();

Expand Down Expand Up @@ -224,7 +203,7 @@ function moveNodeUp(
function moveNodeDown(
event: KeyboardEvent,
container: HTMLDivElement,
outerThis: any,
outerThis: any
) {
event.preventDefault();

Expand Down
13 changes: 13 additions & 0 deletions assets/js/hooks/events/listener/focus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getNodeByEvent } from "../../node";

export function focusin(event: FocusEvent) {
const { uuid } = getNodeByEvent(event);

this.pushEvent("set_focus", uuid);
}

export function focusout(event: FocusEvent) {
const { uuid } = getNodeByEvent(event);

this.pushEvent("remove_focus", uuid);
}
10 changes: 10 additions & 0 deletions assets/js/hooks/events/listener/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getNodeByEvent } from "../../node";
import { getItemByNode, setItemDirty } from "../../item";

export function input(event: Event) {
const node = getNodeByEvent(event);
const item = getItemByNode(node);
item && setItemDirty(item, true);

this.pushEvent("update_node_content", node);
}
4 changes: 3 additions & 1 deletion assets/js/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { focusin, focusout, input, keydown } from "./events/listener";
import { focusin, focusout } from "./events/listener/focus";
import { input } from "./events/listener/input";
import { keydown } from "./events/listener";
import {
handleList,
handleInsert,
Expand Down

0 comments on commit 9e7632f

Please sign in to comment.