-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add "new" btn + fix shared states
- Loading branch information
Showing
12 changed files
with
228 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Lato&family=Roboto+Flex:[email protected]&display=swap'); | ||
|
||
/* fallback */ | ||
@font-face { | ||
font-family: 'Material Symbols Outlined'; | ||
font-style: normal; | ||
font-weight: 100 700; | ||
src: url(https://fonts.gstatic.com/s/materialsymbolsoutlined/v26/kJEhBvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oFsI.woff2) format('woff2'); | ||
} | ||
|
||
html, | ||
body, | ||
#__nuxt { | ||
|
@@ -6,13 +16,8 @@ body, | |
height: 100%; | ||
width: 100%; | ||
} | ||
/* fallback */ | ||
@font-face { | ||
font-family: 'Material Symbols Outlined'; | ||
font-style: normal; | ||
font-weight: 100 700; | ||
src: url(https://fonts.gstatic.com/s/materialsymbolsoutlined/v26/kJEhBvYX7BgnkSrUwT8OhrdQw4oELdPIeeII9v6oFsI.woff2) format('woff2'); | ||
} | ||
|
||
|
||
|
||
.icon { | ||
font-family: 'Material Symbols Outlined'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<div class="trs_filename" @click="handleCreateFile"> | ||
<div class="trs_plusbtn"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"> | ||
<!--! Font Awesome Pro 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --> | ||
<path | ||
d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z" | ||
/> | ||
</svg> | ||
</div> | ||
<input | ||
v-show="creationStatus == 'editing'" | ||
type="text" | ||
v-model="btnName" | ||
ref="newFilename" | ||
class="newFileInput" | ||
@keypress="handleKeyPress" | ||
@focusout="handleUnfocus" | ||
/> | ||
<span v-if="creationStatus == 'initial'">{{ btnName }}</span> | ||
<span v-if="creationStatus == 'creating'">Création...</span> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { PropType, Ref } from "vue"; | ||
import { basicFileData } from "@/server/api/getDirectoryListing"; | ||
const btnName = ref("Créer une nouvelle catégorie"); | ||
const creationStatus = ref("initial"); | ||
const newFilename: Ref<HTMLInputElement> = ref(null); | ||
const props = defineProps({ | ||
parentData: { | ||
type: Object as PropType<basicFileData | null>, | ||
required: false, | ||
default: () => null, | ||
}, | ||
}); | ||
if (props.parentData?.filename) { | ||
btnName.value = `Nouv. page sur ${props.parentData.filename}`; | ||
} | ||
function handleCreateFile() { | ||
if (creationStatus.value !== "initial") { | ||
return; | ||
} | ||
creationStatus.value = "editing"; | ||
btnName.value = "nouv fichier"; | ||
nextTick(() => { | ||
newFilename.value.focus(); | ||
newFilename.value.select(); | ||
}); | ||
} | ||
function handleKeyPress(e: KeyboardEvent) { | ||
if (e.key === "Enter") { | ||
newFilename.value.blur(); | ||
} | ||
} | ||
function handleUnfocus() { | ||
creationStatus.value = "creating"; | ||
} | ||
</script> | ||
<style lang="scss"> | ||
@use "assets/css/defs.scss"; | ||
.trs_plusbtn { | ||
@include defs.tsr_use_file_btn_container; | ||
@include defs.trs_use_filename_fill; | ||
} | ||
.trs_plusbtn svg { | ||
width: 10px; | ||
height: 10px; | ||
} | ||
.newFileInput { | ||
@include defs.trs_use_selected_bg_color; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<div class="flex-1" data-do-stop-propagation="yes" @click="handleClick"> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { useReactiveGlobalState } from "@/stores/trsEditorFiles"; | ||
import { trsGetActionByClickEvent } from "@/composables/trs/TrsDirClickWatcher"; | ||
const state = useReactiveGlobalState(); | ||
function handleClick(e: MouseEvent) { | ||
const { action, details } = trsGetActionByClickEvent(e); | ||
switch (action) { | ||
case "expandFile": | ||
toggleFileExpandingState(details); | ||
break; | ||
case "changeFile": | ||
changeDoc(details); | ||
break; | ||
default: | ||
console.log("Unhandled action", action, e); | ||
} | ||
} | ||
function toggleFileExpandingState(docId: string) { | ||
const fileAsNumber = parseInt(docId, 10); | ||
if (state.openedIds.value.has(fileAsNumber)) { | ||
state.openedIds.value.delete(fileAsNumber); | ||
} else { | ||
state.openedIds.value.add(fileAsNumber); | ||
} | ||
} | ||
function changeDoc(docId: string) { | ||
state.activeFile.value = parseInt(docId, 10); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export function trsGetActionByClickEvent(event: MouseEvent): { | ||
action: string; | ||
details?: string; | ||
} { | ||
let currentElement: HTMLElement = event.target as HTMLElement; | ||
let action = "unknown"; | ||
let details: string | undefined = undefined; | ||
|
||
while (currentElement) { | ||
if (currentElement.dataset.doExpandFile) { | ||
action = "expandFile"; | ||
details = currentElement.dataset.doExpandFile; | ||
break; | ||
} | ||
if (currentElement.dataset.doChangeFile) { | ||
action = "changeFile"; | ||
details = currentElement.dataset.doChangeFile; | ||
break; | ||
} | ||
if (currentElement.dataset.doStopPropagation) { | ||
action = "stopPropagation"; | ||
break; | ||
} | ||
currentElement = currentElement.parentElement; | ||
} | ||
return { action, details }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.