wait a tick before emitting new Id in SelectMotion
This commit is contained in:
parent
ec1f069515
commit
eb472e2d76
|
@ -49,9 +49,27 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, defineEmits, defineProps } from 'vue'
|
import { computed, defineEmits, defineProps, nextTick } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
selectedId: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
getAddValue: {
|
||||||
|
type: Function,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const props = defineProps(['modelValue', 'selectedId', 'disabled', 'getAddValue'])
|
|
||||||
const emit = defineEmits(['update:modelValue', 'update:selectedId'])
|
const emit = defineEmits(['update:modelValue', 'update:selectedId'])
|
||||||
|
|
||||||
const moveUpValid = computed(() => {
|
const moveUpValid = computed(() => {
|
||||||
|
@ -60,12 +78,13 @@ const moveUpValid = computed(() => {
|
||||||
|
|
||||||
const present = computed(() => props.modelValue[props.selectedId] != null)
|
const present = computed(() => props.modelValue[props.selectedId] != null)
|
||||||
|
|
||||||
const moveUp = () => {
|
const moveUp = async () => {
|
||||||
const newModel = [...props.modelValue]
|
const newModel = [...props.modelValue]
|
||||||
const movable = newModel.splice(props.selectedId, 1)[0]
|
const movable = newModel.splice(props.selectedId, 1)[0]
|
||||||
newModel.splice(props.selectedId - 1, 0, movable)
|
newModel.splice(props.selectedId - 1, 0, movable)
|
||||||
|
|
||||||
emit('update:modelValue', newModel)
|
emit('update:modelValue', newModel)
|
||||||
|
await nextTick()
|
||||||
emit('update:selectedId', props.selectedId - 1)
|
emit('update:selectedId', props.selectedId - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,27 +92,30 @@ const moveDnValid = computed(() => {
|
||||||
return props.selectedId < props.modelValue.length - 1
|
return props.selectedId < props.modelValue.length - 1
|
||||||
})
|
})
|
||||||
|
|
||||||
const moveDn = () => {
|
const moveDn = async () => {
|
||||||
const newModel = [...props.modelValue]
|
const newModel = [...props.modelValue]
|
||||||
const movable = newModel.splice(props.selectedId.value, 1)[0]
|
const movable = newModel.splice(props.selectedId.value, 1)[0]
|
||||||
newModel.splice(props.selectedId + 1, 0, movable)
|
newModel.splice(props.selectedId + 1, 0, movable)
|
||||||
|
|
||||||
emit('update:modelValue', newModel)
|
emit('update:modelValue', newModel)
|
||||||
|
await nextTick()
|
||||||
emit('update:selectedId', props.selectedId + 1)
|
emit('update:selectedId', props.selectedId + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const add = () => {
|
const add = async () => {
|
||||||
const newModel = [...props.modelValue, props.getAddValue()]
|
const newModel = [...props.modelValue, props.getAddValue()]
|
||||||
|
|
||||||
emit('update:modelValue', newModel)
|
emit('update:modelValue', newModel)
|
||||||
|
await nextTick()
|
||||||
emit('update:selectedId', Math.max(newModel.length - 1, 0))
|
emit('update:selectedId', Math.max(newModel.length - 1, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
const del = () => {
|
const del = async () => {
|
||||||
const newModel = [...props.modelValue]
|
const newModel = [...props.modelValue]
|
||||||
newModel.splice(props.selectedId, 1)
|
newModel.splice(props.selectedId, 1)
|
||||||
|
|
||||||
emit('update:modelValue', newModel)
|
emit('update:modelValue', newModel)
|
||||||
|
await nextTick()
|
||||||
emit('update:selectedId', newModel.length === 0 ? undefined : Math.max(props.selectedId - 1, 0))
|
emit('update:selectedId', newModel.length === 0 ? undefined : Math.max(props.selectedId - 1, 0))
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script src="./virtual_directives_tab.js"></script>
|
<script src="./virtual_directives_tab.js"></script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="setting-item list-editor variables-editor">
|
<div class="setting-item list-editor variables-editor">
|
||||||
<label
|
<label
|
||||||
class="list-select-label"
|
class="list-select-label"
|
||||||
for="variables-selector"
|
for="variables-selector"
|
||||||
|
@ -79,5 +79,5 @@
|
||||||
:hide-optional-checkbox="true"
|
:hide-optional-checkbox="true"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in a new issue