-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node library custom bookmark folder (#631)
* Add new folder button * Add tree util test * nit * Support empty folder in node library * Drag to bookmark folder * Use bookmark icon for bookmark folder * Highlight on dragover * nit * Auto-expand on item added * Extract bookmark system as store * Add context menu on bookmark folder * Add editable text * Fix reactivity * Plumb editable text * refactor * Rename node * Fix focus * Prevent name collision * nit * Add new folder * nested folder support * Change drag behavior * Add basic playwright tests * nit * Target tree-node-content instead of tree-node
- Loading branch information
Showing
10 changed files
with
692 additions
and
82 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
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,81 @@ | ||
<template> | ||
<div class="editable-text"> | ||
<span v-if="!props.isEditing"> | ||
{{ modelValue }} | ||
</span> | ||
<InputText | ||
v-else | ||
type="text" | ||
size="small" | ||
fluid | ||
v-model:modelValue="inputValue" | ||
ref="inputRef" | ||
@keyup.enter="finishEditing" | ||
@click.stop | ||
:pt="{ | ||
root: { | ||
onBlur: finishEditing | ||
} | ||
}" | ||
v-focus | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import InputText from 'primevue/inputtext' | ||
import { nextTick, ref, watch } from 'vue' | ||
interface EditableTextProps { | ||
modelValue: string | ||
isEditing?: boolean | ||
} | ||
const props = withDefaults(defineProps<EditableTextProps>(), { | ||
isEditing: false | ||
}) | ||
const emit = defineEmits(['update:modelValue', 'edit']) | ||
const inputValue = ref<string>(props.modelValue) | ||
const isEditingFinished = ref<boolean>(false) | ||
const inputRef = ref(null) | ||
const finishEditing = () => { | ||
if (isEditingFinished.value) { | ||
return | ||
} | ||
isEditingFinished.value = true | ||
emit('edit', inputValue.value) | ||
} | ||
watch( | ||
() => props.isEditing, | ||
(newVal) => { | ||
if (newVal) { | ||
inputValue.value = props.modelValue | ||
isEditingFinished.value = false | ||
nextTick(() => { | ||
if (!inputRef.value) return | ||
const fileName = inputValue.value.includes('.') | ||
? inputValue.value.split('.').slice(0, -1).join('.') | ||
: inputValue.value | ||
const start = 0 | ||
const end = fileName.length | ||
const inputElement = inputRef.value.$el | ||
inputElement.setSelectionRange(start, end) | ||
}) | ||
} | ||
} | ||
) | ||
const vFocus = { | ||
mounted: (el: HTMLElement) => el.focus() | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.editable-text { | ||
display: inline-block; | ||
} | ||
.editable-text input { | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
</style> |
Oops, something went wrong.