From 6e96ae7fd487cf64f4eff1deec2df0210f9edd08 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 12 Feb 2025 01:05:38 +0100 Subject: [PATCH] Implement controls for new UI state --- gdn-app/src/App.vue | 7 +- gdn-app/src/components/CNote.vue | 102 ++++++++++++++++---- gdn-app/src/components/CNoteButton.vue | 2 +- gdn-app/src/components/CNoteChildEditor.vue | 23 +++++ gdn-app/src/components/CNoteEditor.vue | 1 + 5 files changed, 113 insertions(+), 22 deletions(-) create mode 100644 gdn-app/src/components/CNoteChildEditor.vue diff --git a/gdn-app/src/App.vue b/gdn-app/src/App.vue index 3d13ced..6204015 100644 --- a/gdn-app/src/App.vue +++ b/gdn-app/src/App.vue @@ -9,7 +9,12 @@ const ui = useUiStore(); window.addEventListener("keypress", (ev) => { if (document.activeElement !== document.body) return; - if (ev.key === "Escape" && ui.mode === "focus") { + if (ev.key === "Escape") { + if (ui.mode !== "focus") { + ui.focus(); + return; + } + const parent = ui.focusPath.parent(); if (parent) ui.focusOn(parent); return; diff --git a/gdn-app/src/components/CNote.vue b/gdn-app/src/components/CNote.vue index 21fe428..522d9d3 100644 --- a/gdn-app/src/components/CNote.vue +++ b/gdn-app/src/components/CNote.vue @@ -3,10 +3,12 @@ import { Path, Segment } from "@/lib/path"; import { useNotesStore } from "@/stores/notes"; import { useUiStore } from "@/stores/ui"; import { - RiAddLine, RiArrowDownSLine, + RiArrowDownWideLine, RiArrowRightDoubleLine, RiArrowRightSLine, + RiArrowUpWideLine, + RiCornerDownRightLine, RiCornerUpRightLine, RiEditLine, RiPushpinFill, @@ -14,6 +16,7 @@ import { } from "@remixicon/vue"; import { computed, ref, watchEffect } from "vue"; import CNoteButton from "./CNoteButton.vue"; +import CNoteChildEditor from "./CNoteChildEditor.vue"; import CNoteEditor from "./CNoteEditor.vue"; const notes = useNotesStore(); @@ -23,11 +26,13 @@ const { path, segment, parentId, + parentIndex = 0, forceOpen = false, } = defineProps<{ path: Path; // From root to here segment: Segment; parentId?: string; + parentIndex?: number; forceOpen?: boolean; }>(); @@ -54,7 +59,6 @@ const children = computed(() => { }); const hovering = ref(false); -const hover = computed(() => hovering.value && !editing.value); const mayOpen = computed(() => children.value.length > 0); const open = computed(() => mayOpen.value && ui.isOpen(path)); @@ -78,9 +82,20 @@ function onClick(): void { ui.toggleOpen(path); } -function onPinButtonClick(): void { - if (pinned.value) ui.unsetPinned(); - else ui.setPinned(segment, parentId); +function onInsertSiblingBeforeButtonClick(): void { + const parent = path.parent(); + if (!parent) return; + ui.insertAt(parent, parentIndex); +} + +function onInsertSiblingAfterButtonClick(): void { + const parent = path.parent(); + if (!parent) return; + ui.insertAt(parent, parentIndex + 1); +} + +function onInsertChildButtonClick(): void { + ui.insertAt(path, children.value.length); } function onEditButtonClick(): void { @@ -98,9 +113,29 @@ function onEditEditorFinish(text: string): void { onEditEditorClose(); } +function onPinButtonClick(): void { + if (pinned.value) ui.unsetPinned(); + else ui.setPinned(segment, parentId); +} + function onMoveButtonClick(): void { ui.pushAnchorId(segment.id); } + +function onInsertEditorClose(): void { + ui.focus(); +} + +function onInsertEditorFinish(text: string): void { + if (!note.value) return; + + if (insertIndex.value !== undefined) { + const childNote = notes.createNote(text); + note.value.children.splice(insertIndex.value, 0, childNote.id); + } + + onInsertEditorClose(); +}