2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-06-02 15:43:30 +00:00
|
|
|
<div :class="cx('root')" v-bind="ptm('root')">
|
|
|
|
<div v-if="showSourceControls" :class="cx('sourceControls')" v-bind="ptm('sourceControls')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="sourcecontrolsstart"></slot>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveUpAriaLabel" :disabled="moveDisabled(0)" type="button" @click="moveUp($event, 0)" :pt="ptm('sourceMoveUpButton')" v-bind="moveUpButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="moveupicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleUpIcon v-bind="ptm('sourceMoveUpButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveTopAriaLabel" :disabled="moveDisabled(0)" type="button" @click="moveTop($event, 0)" :pt="ptm('sourceMoveTopButton')" v-bind="moveTopButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="movetopicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleDoubleUpIcon v-bind="ptm('sourceMoveTopButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveDownAriaLabel" :disabled="moveDisabled(0)" type="button" @click="moveDown($event, 0)" :pt="ptm('sourceMoveDownButton')" v-bind="moveDownButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="movedownicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleDownIcon v-bind="ptm('sourceMoveDownButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveBottomAriaLabel" :disabled="moveDisabled(0)" type="button" @click="moveBottom($event, 0)" :pt="ptm('sourceMoveBottomButton')" v-bind="moveBottomButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="movebottomicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleDoubleDownIcon v-bind="ptm('sourceMoveBottomButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="sourcecontrolsend"></slot>
|
|
|
|
</div>
|
2023-06-02 15:43:30 +00:00
|
|
|
<div :class="cx('sourceWrapper')" v-bind="ptm('sourceWrapper')">
|
2023-06-06 13:30:04 +00:00
|
|
|
<div v-if="$slots.sourceheader" :class="cx('sourceHeader')" v-bind="ptm('sourceHeader')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="sourceheader"></slot>
|
|
|
|
</div>
|
2022-12-08 11:04:25 +00:00
|
|
|
<transition-group
|
|
|
|
ref="sourceList"
|
|
|
|
:id="idSource + '_list'"
|
|
|
|
name="p-picklist-flip"
|
|
|
|
tag="ul"
|
2023-06-02 15:43:30 +00:00
|
|
|
:class="cx('sourceList')"
|
2022-12-08 11:04:25 +00:00
|
|
|
:style="listStyle"
|
|
|
|
role="listbox"
|
|
|
|
aria-multiselectable="true"
|
|
|
|
:aria-activedescendant="focused['sourceList'] ? focusedOptionId : undefined"
|
|
|
|
:tabindex="sourceList && sourceList.length > 0 ? tabindex : -1"
|
|
|
|
@focus="onListFocus($event, 'sourceList')"
|
|
|
|
@blur="onListBlur($event, 'sourceList')"
|
|
|
|
@keydown="onItemKeyDown($event, 'sourceList')"
|
2023-05-09 22:03:24 +00:00
|
|
|
v-bind="{ ...sourceListProps, ...ptm('sourceList') }"
|
2022-12-08 11:04:25 +00:00
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-for="(item, i) of sourceList" :key="getItemKey(item, i)">
|
2022-09-14 11:26:01 +00:00
|
|
|
<li
|
2022-12-08 11:04:25 +00:00
|
|
|
:id="idSource + '_' + i"
|
2022-09-14 11:26:01 +00:00
|
|
|
v-ripple
|
2023-07-13 08:00:06 +00:00
|
|
|
:class="cx('item', { item, id: `${idSource}_${i}`, listIndex: 0 })"
|
2022-12-08 11:04:25 +00:00
|
|
|
@click="onItemClick($event, item, i, 0)"
|
2022-09-14 11:26:01 +00:00
|
|
|
@dblclick="onItemDblClick($event, item, 0)"
|
|
|
|
@touchend="onItemTouchEnd"
|
2023-01-09 18:19:45 +00:00
|
|
|
@mousedown="onOptionMouseDown(i, 'sourceList')"
|
2022-09-14 11:26:01 +00:00
|
|
|
role="option"
|
|
|
|
:aria-selected="isSelected(item, 0)"
|
2023-07-13 08:00:06 +00:00
|
|
|
v-bind="getPTOptions(item, 'item', `${idSource}_${i}`, 0)"
|
2023-06-06 13:30:04 +00:00
|
|
|
:data-p-highlight="isSelected(item, 0)"
|
2023-07-13 07:42:00 +00:00
|
|
|
:data-p-focused="`${idSource}_${i}` === focusedOptionId"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="item" :item="item" :index="i"> </slot>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</transition-group>
|
|
|
|
</div>
|
2023-06-02 15:43:30 +00:00
|
|
|
<div :class="cx('buttons')" v-bind="ptm('buttons')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="movecontrolsstart"></slot>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveToTargetAriaLabel" type="button" @click="moveToTarget" :disabled="moveDisabled(0)" :pt="ptm('moveToTargetButton')" v-bind="moveToTargetProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
2023-04-18 13:55:04 +00:00
|
|
|
<slot name="movetotargeticon" :viewChanged="viewChanged">
|
2023-05-09 22:03:24 +00:00
|
|
|
<component :is="viewChanged ? 'AngleDownIcon' : 'AngleRightIcon'" v-bind="ptm('moveToTargetButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveAllToTargetAriaLabel" type="button" @click="moveAllToTarget" :disabled="moveAllDisabled('sourceList')" :pt="ptm('moveAllToTargetButton')" v-bind="moveAllToTargetProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
2023-04-18 13:55:04 +00:00
|
|
|
<slot name="movealltotargeticon" :viewChanged="viewChanged">
|
2023-05-09 22:03:24 +00:00
|
|
|
<component :is="viewChanged ? 'AngleDoubleDownIcon' : 'AngleDoubleRightIcon'" v-bind="ptm('moveAllToTargetButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveToSourceAriaLabel" type="button" @click="moveToSource" :disabled="moveDisabled(1)" :pt="ptm('moveToSourceButton')" v-bind="moveToSourceProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
2023-04-18 13:55:04 +00:00
|
|
|
<slot name="movetosourceicon" :viewChanged="viewChanged">
|
2023-05-09 22:03:24 +00:00
|
|
|
<component :is="viewChanged ? 'AngleUpIcon' : 'AngleLeftIcon'" v-bind="ptm('moveToSourceButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveAllToSourceAriaLabel" type="button" @click="moveAllToSource" :disabled="moveSourceDisabled('targetList')" :pt="ptm('moveAllToSourceButton')" v-bind="moveAllToSourceProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
2023-04-18 13:55:04 +00:00
|
|
|
<slot name="movealltosourceicon" :viewChanged="viewChanged">
|
2023-05-09 22:03:24 +00:00
|
|
|
<component :is="viewChanged ? 'AngleDoubleUpIcon' : 'AngleDoubleLeftIcon'" v-bind="ptm('moveAllToSourceButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="movecontrolsend"></slot>
|
|
|
|
</div>
|
2023-06-02 15:43:30 +00:00
|
|
|
<div :class="cx('targetWrapper')" v-bind="ptm('targetWrapper')">
|
|
|
|
<div v-if="$slots.targetheader" :class="cx('targetHeader')" v-bind="ptm('targetHeader')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="targetheader"></slot>
|
|
|
|
</div>
|
2022-12-08 11:04:25 +00:00
|
|
|
<transition-group
|
|
|
|
ref="targetList"
|
|
|
|
:id="idTarget + '_list'"
|
|
|
|
name="p-picklist-flip"
|
|
|
|
tag="ul"
|
2023-06-02 15:43:30 +00:00
|
|
|
:class="cx('targetList')"
|
2022-12-08 11:04:25 +00:00
|
|
|
:style="listStyle"
|
|
|
|
role="listbox"
|
|
|
|
aria-multiselectable="true"
|
|
|
|
:aria-activedescendant="focused['targetList'] ? focusedOptionId : undefined"
|
|
|
|
:tabindex="targetList && targetList.length > 0 ? tabindex : -1"
|
|
|
|
@focus="onListFocus($event, 'targetList')"
|
|
|
|
@blur="onListBlur($event, 'targetList')"
|
|
|
|
@keydown="onItemKeyDown($event, 'targetList')"
|
2023-05-09 22:03:24 +00:00
|
|
|
v-bind="{ ...targetListProps, ...ptm('targetList') }"
|
2022-12-08 11:04:25 +00:00
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-for="(item, i) of targetList" :key="getItemKey(item, i)">
|
2022-09-14 11:26:01 +00:00
|
|
|
<li
|
2022-12-08 11:04:25 +00:00
|
|
|
:id="idTarget + '_' + i"
|
2022-09-14 11:26:01 +00:00
|
|
|
v-ripple
|
2023-07-13 08:00:06 +00:00
|
|
|
:class="cx('item', { item, id: `${idTarget}_${i}`, listIndex: 1 })"
|
2022-12-08 11:04:25 +00:00
|
|
|
@click="onItemClick($event, item, i, 1)"
|
2022-09-14 11:26:01 +00:00
|
|
|
@dblclick="onItemDblClick($event, item, 1)"
|
2022-12-08 11:04:25 +00:00
|
|
|
@keydown="onItemKeyDown($event, 'targetList')"
|
2023-01-09 18:19:45 +00:00
|
|
|
@mousedown="onOptionMouseDown(i, 'targetList')"
|
2022-09-14 11:26:01 +00:00
|
|
|
@touchend="onItemTouchEnd"
|
|
|
|
role="option"
|
|
|
|
:aria-selected="isSelected(item, 1)"
|
2023-07-13 08:00:06 +00:00
|
|
|
v-bind="getPTOptions(item, 'item', `${idTarget}_${i}`, 1)"
|
2023-06-06 13:30:04 +00:00
|
|
|
:data-p-highlight="isSelected(item, 1)"
|
2023-07-13 07:42:00 +00:00
|
|
|
:data-p-focused="`${idTarget}_${i}` === focusedOptionId"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="item" :item="item" :index="i"> </slot>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
</transition-group>
|
|
|
|
</div>
|
2023-06-02 15:43:30 +00:00
|
|
|
<div v-if="showTargetControls" :class="cx('targetControls')" v-bind="ptm('targetControls')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="targetcontrolsstart"></slot>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveUpAriaLabel" :disabled="moveDisabled(1)" type="button" @click="moveUp($event, 1)" :pt="ptm('targetMoveUpButton')" v-bind="moveUpButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="moveupicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleUpIcon v-bind="ptm('targetMoveUpButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveTopAriaLabel" :disabled="moveDisabled(1)" type="button" @click="moveTop($event, 1)" :pt="ptm('targetMoveTopButton')" v-bind="moveTopButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="movetopicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleDoubleUpIcon v-bind="ptm('targetMoveTopButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveDownAriaLabel" :disabled="moveDisabled(1)" type="button" @click="moveDown($event, 1)" :pt="ptm('targetMoveDownButton')" v-bind="moveDownButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="movedownicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleDownIcon v-bind="ptm('targetMoveDownButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2023-07-13 07:42:00 +00:00
|
|
|
<PLButton :aria-label="moveBottomAriaLabel" :disabled="moveDisabled(1)" type="button" @click="moveBottom($event, 1)" :pt="ptm('targetMoveBottomButton')" v-bind="moveBottomButtonProps" :unstyled="unstyled">
|
2023-04-14 07:44:20 +00:00
|
|
|
<template #icon>
|
|
|
|
<slot name="movebottomicon">
|
2023-05-09 22:03:24 +00:00
|
|
|
<AngleDoubleDownIcon v-bind="ptm('targetMoveBottomButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-07 06:47:43 +00:00
|
|
|
</PLButton>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="targetcontrolsend"></slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Button from 'primevue/button';
|
2023-04-18 12:53:43 +00:00
|
|
|
import AngleDoubleDownIcon from 'primevue/icons/angledoubledown';
|
|
|
|
import AngleDoubleLeftIcon from 'primevue/icons/angledoubleleft';
|
|
|
|
import AngleDoubleRightIcon from 'primevue/icons/angledoubleright';
|
|
|
|
import AngleDoubleUpIcon from 'primevue/icons/angledoubleup';
|
|
|
|
import AngleDownIcon from 'primevue/icons/angledown';
|
|
|
|
import AngleLeftIcon from 'primevue/icons/angleleft';
|
|
|
|
import AngleRightIcon from 'primevue/icons/angleright';
|
|
|
|
import AngleUpIcon from 'primevue/icons/angleup';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
|
2023-06-05 10:19:03 +00:00
|
|
|
import BasePickList from './BasePickList.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'PickList',
|
2023-06-02 15:43:30 +00:00
|
|
|
extends: BasePickList,
|
2022-12-08 11:04:25 +00:00
|
|
|
emits: ['update:modelValue', 'reorder', 'update:selection', 'selection-change', 'move-to-target', 'move-to-source', 'move-all-to-target', 'move-all-to-source', 'focus', 'blur'],
|
2022-09-06 12:03:37 +00:00
|
|
|
itemTouched: false,
|
|
|
|
reorderDirection: null,
|
|
|
|
styleElement: null,
|
2023-04-18 13:55:04 +00:00
|
|
|
media: null,
|
|
|
|
mediaChangeListener: null,
|
2022-09-06 12:03:37 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2023-01-19 04:01:03 +00:00
|
|
|
id: this.$attrs.id,
|
2022-12-08 11:04:25 +00:00
|
|
|
d_selection: this.selection,
|
|
|
|
focused: {
|
|
|
|
sourceList: false,
|
|
|
|
targetList: false
|
|
|
|
},
|
2023-04-18 13:55:04 +00:00
|
|
|
focusedOptionIndex: -1,
|
|
|
|
viewChanged: false
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
2023-01-19 04:01:03 +00:00
|
|
|
'$attrs.id': function (newValue) {
|
|
|
|
this.id = newValue || UniqueComponentId();
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
selection(newValue) {
|
|
|
|
this.d_selection = newValue;
|
2023-04-18 13:55:04 +00:00
|
|
|
},
|
|
|
|
breakpoint(newValue) {
|
|
|
|
this.destroyMedia();
|
|
|
|
this.initMedia();
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
if (this.reorderDirection) {
|
|
|
|
this.updateListScroll(this.$refs.sourceList.$el);
|
|
|
|
this.updateListScroll(this.$refs.targetList.$el);
|
|
|
|
this.reorderDirection = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
this.destroyStyle();
|
2023-04-18 13:55:04 +00:00
|
|
|
this.destroyMedia();
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2023-01-19 04:01:03 +00:00
|
|
|
this.id = this.id || UniqueComponentId();
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.responsive) {
|
|
|
|
this.createStyle();
|
2023-04-18 13:55:04 +00:00
|
|
|
this.initMedia();
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getItemKey(item, index) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.dataKey ? ObjectUtils.resolveFieldData(item, this.dataKey) : index;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-07-13 07:42:00 +00:00
|
|
|
getPTOptions(item, key, id, listIndex) {
|
2023-05-09 22:03:24 +00:00
|
|
|
return this.ptm(key, {
|
|
|
|
context: {
|
2023-07-13 07:42:00 +00:00
|
|
|
active: this.isSelected(item, listIndex),
|
|
|
|
focused: id === this.focusedOptionId
|
2023-05-09 22:03:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
isSelected(item, listIndex) {
|
|
|
|
return ObjectUtils.findIndexInList(item, this.d_selection[listIndex]) != -1;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onListFocus(event, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const selectedFirstItem = DomHandler.findSingle(this.$refs[listType].$el, '[data-p-highlight="true"]');
|
2023-01-09 18:19:45 +00:00
|
|
|
const findIndex = ObjectUtils.findIndexInList(selectedFirstItem, this.$refs[listType].$el.children);
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
this.focused[listType] = true;
|
2023-01-09 18:19:45 +00:00
|
|
|
|
|
|
|
const index = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : selectedFirstItem ? findIndex : -1;
|
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
this.changeFocusedOptionIndex(index, listType);
|
|
|
|
this.$emit('focus', event);
|
|
|
|
},
|
|
|
|
onListBlur(event, listType) {
|
|
|
|
this.focused[listType] = false;
|
|
|
|
this.focusedOptionIndex = -1;
|
|
|
|
this.$emit('blur', event);
|
|
|
|
},
|
2023-01-09 18:19:45 +00:00
|
|
|
onOptionMouseDown(index, listType) {
|
|
|
|
this.focused[listType] = true;
|
|
|
|
this.focusedOptionIndex = index;
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
moveUp(event, listIndex) {
|
|
|
|
if (this.d_selection && this.d_selection[listIndex]) {
|
|
|
|
let valueList = [...this.modelValue[listIndex]];
|
|
|
|
let selectionList = this.d_selection[listIndex];
|
|
|
|
|
|
|
|
for (let i = 0; i < selectionList.length; i++) {
|
|
|
|
let selectedItem = selectionList[i];
|
|
|
|
let selectedItemIndex = ObjectUtils.findIndexInList(selectedItem, valueList);
|
|
|
|
|
|
|
|
if (selectedItemIndex !== 0) {
|
|
|
|
let movedItem = valueList[selectedItemIndex];
|
|
|
|
let temp = valueList[selectedItemIndex - 1];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
valueList[selectedItemIndex - 1] = movedItem;
|
|
|
|
valueList[selectedItemIndex] = temp;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[listIndex] = valueList;
|
|
|
|
|
|
|
|
this.reorderDirection = 'up';
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
this.$emit('reorder', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: value,
|
|
|
|
direction: this.reorderDirection,
|
|
|
|
listIndex: listIndex
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveTop(event, listIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.d_selection) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let valueList = [...this.modelValue[listIndex]];
|
|
|
|
let selectionList = this.d_selection[listIndex];
|
|
|
|
|
|
|
|
for (let i = 0; i < selectionList.length; i++) {
|
|
|
|
let selectedItem = selectionList[i];
|
|
|
|
let selectedItemIndex = ObjectUtils.findIndexInList(selectedItem, valueList);
|
|
|
|
|
|
|
|
if (selectedItemIndex !== 0) {
|
|
|
|
let movedItem = valueList.splice(selectedItemIndex, 1)[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
valueList.unshift(movedItem);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[listIndex] = valueList;
|
|
|
|
|
|
|
|
this.reorderDirection = 'top';
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
this.$emit('reorder', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: value,
|
|
|
|
direction: this.reorderDirection,
|
|
|
|
listIndex: listIndex
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveDown(event, listIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.d_selection) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let valueList = [...this.modelValue[listIndex]];
|
|
|
|
let selectionList = this.d_selection[listIndex];
|
|
|
|
|
|
|
|
for (let i = selectionList.length - 1; i >= 0; i--) {
|
|
|
|
let selectedItem = selectionList[i];
|
|
|
|
let selectedItemIndex = ObjectUtils.findIndexInList(selectedItem, valueList);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (selectedItemIndex !== valueList.length - 1) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let movedItem = valueList[selectedItemIndex];
|
|
|
|
let temp = valueList[selectedItemIndex + 1];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
valueList[selectedItemIndex + 1] = movedItem;
|
|
|
|
valueList[selectedItemIndex] = temp;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[listIndex] = valueList;
|
|
|
|
|
|
|
|
this.reorderDirection = 'down';
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
this.$emit('reorder', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: value,
|
|
|
|
direction: this.reorderDirection,
|
|
|
|
listIndex: listIndex
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveBottom(event, listIndex) {
|
|
|
|
if (this.d_selection) {
|
|
|
|
let valueList = [...this.modelValue[listIndex]];
|
|
|
|
let selectionList = this.d_selection[listIndex];
|
|
|
|
|
|
|
|
for (let i = selectionList.length - 1; i >= 0; i--) {
|
|
|
|
let selectedItem = selectionList[i];
|
|
|
|
let selectedItemIndex = ObjectUtils.findIndexInList(selectedItem, valueList);
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (selectedItemIndex !== valueList.length - 1) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let movedItem = valueList.splice(selectedItemIndex, 1)[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
valueList.push(movedItem);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[listIndex] = valueList;
|
|
|
|
|
|
|
|
this.reorderDirection = 'bottom';
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
this.$emit('reorder', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: value,
|
|
|
|
direction: this.reorderDirection,
|
|
|
|
listIndex: listIndex
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveToTarget(event) {
|
|
|
|
let selection = this.d_selection && this.d_selection[0] ? this.d_selection[0] : null;
|
|
|
|
let sourceList = [...this.modelValue[0]];
|
|
|
|
let targetList = [...this.modelValue[1]];
|
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
for (let i = 0; i < selection.length; i++) {
|
|
|
|
let selectedItem = selection[i];
|
|
|
|
|
|
|
|
if (ObjectUtils.findIndexInList(selectedItem, targetList) == -1) {
|
2022-09-14 11:26:01 +00:00
|
|
|
targetList.push(sourceList.splice(ObjectUtils.findIndexInList(selectedItem, sourceList), 1)[0]);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[0] = sourceList;
|
|
|
|
value[1] = targetList;
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
|
|
|
|
this.$emit('move-to-target', {
|
|
|
|
originalEvent: event,
|
|
|
|
items: selection
|
|
|
|
});
|
|
|
|
|
|
|
|
this.d_selection[0] = [];
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
this.$emit('selection-change', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: this.d_selection
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveAllToTarget(event) {
|
|
|
|
if (this.modelValue[0]) {
|
|
|
|
let sourceList = [...this.modelValue[0]];
|
|
|
|
let targetList = [...this.modelValue[1]];
|
|
|
|
|
|
|
|
this.$emit('move-all-to-target', {
|
|
|
|
originalEvent: event,
|
|
|
|
items: sourceList
|
|
|
|
});
|
|
|
|
|
|
|
|
targetList = [...targetList, ...sourceList];
|
|
|
|
sourceList = [];
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[0] = sourceList;
|
|
|
|
value[1] = targetList;
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
|
|
|
|
this.d_selection[0] = [];
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
this.$emit('selection-change', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: this.d_selection
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveToSource(event) {
|
|
|
|
let selection = this.d_selection && this.d_selection[1] ? this.d_selection[1] : null;
|
|
|
|
let sourceList = [...this.modelValue[0]];
|
|
|
|
let targetList = [...this.modelValue[1]];
|
|
|
|
|
|
|
|
if (selection) {
|
|
|
|
for (let i = 0; i < selection.length; i++) {
|
|
|
|
let selectedItem = selection[i];
|
|
|
|
|
|
|
|
if (ObjectUtils.findIndexInList(selectedItem, sourceList) == -1) {
|
2022-09-14 11:26:01 +00:00
|
|
|
sourceList.push(targetList.splice(ObjectUtils.findIndexInList(selectedItem, targetList), 1)[0]);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[0] = sourceList;
|
|
|
|
value[1] = targetList;
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
|
|
|
|
this.$emit('move-to-source', {
|
|
|
|
originalEvent: event,
|
|
|
|
items: selection
|
|
|
|
});
|
|
|
|
|
|
|
|
this.d_selection[1] = [];
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
this.$emit('selection-change', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: this.d_selection
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveAllToSource(event) {
|
|
|
|
if (this.modelValue[1]) {
|
|
|
|
let sourceList = [...this.modelValue[0]];
|
|
|
|
let targetList = [...this.modelValue[1]];
|
|
|
|
|
|
|
|
this.$emit('move-all-to-source', {
|
|
|
|
originalEvent: event,
|
|
|
|
items: targetList
|
|
|
|
});
|
|
|
|
|
|
|
|
sourceList = [...sourceList, ...targetList];
|
|
|
|
targetList = [];
|
|
|
|
|
|
|
|
let value = [...this.modelValue];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
value[0] = sourceList;
|
|
|
|
value[1] = targetList;
|
|
|
|
this.$emit('update:modelValue', value);
|
|
|
|
|
|
|
|
this.d_selection[1] = [];
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
this.$emit('selection-change', {
|
|
|
|
originalEvent: event,
|
|
|
|
value: this.d_selection
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onItemClick(event, item, index, listIndex) {
|
|
|
|
const listType = listIndex === 0 ? 'sourceList' : 'targetList';
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.itemTouched = false;
|
|
|
|
const selectionList = this.d_selection[listIndex];
|
2022-12-08 11:04:25 +00:00
|
|
|
const selectedIndex = ObjectUtils.findIndexInList(item, this.d_selection);
|
2022-09-14 11:26:01 +00:00
|
|
|
const selected = selectedIndex != -1;
|
2022-09-06 12:03:37 +00:00
|
|
|
const metaSelection = this.itemTouched ? false : this.metaKeySelection;
|
2023-06-02 15:43:30 +00:00
|
|
|
const selectedId = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]')[index].getAttribute('id');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
this.focusedOptionIndex = selectedId;
|
2022-09-06 12:03:37 +00:00
|
|
|
let _selection;
|
|
|
|
|
|
|
|
if (metaSelection) {
|
2022-09-14 11:26:01 +00:00
|
|
|
let metaKey = event.metaKey || event.ctrlKey;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (selected && metaKey) {
|
|
|
|
_selection = selectionList.filter((val, index) => index !== selectedIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
_selection = metaKey ? (selectionList ? [...selectionList] : []) : [];
|
2022-09-06 12:03:37 +00:00
|
|
|
_selection.push(item);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (selected) {
|
|
|
|
_selection = selectionList.filter((val, index) => index !== selectedIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
_selection = selectionList ? [...selectionList] : [];
|
|
|
|
_selection.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let newSelection = [...this.d_selection];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
newSelection[listIndex] = _selection;
|
|
|
|
this.d_selection = newSelection;
|
|
|
|
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
this.$emit('selection-change', {
|
2022-09-14 11:26:01 +00:00
|
|
|
originalEvent: event,
|
2022-09-06 12:03:37 +00:00
|
|
|
value: this.d_selection
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onItemDblClick(event, item, listIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (listIndex === 0) this.moveToTarget(event);
|
|
|
|
else if (listIndex === 1) this.moveToSource(event);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onItemTouchEnd() {
|
|
|
|
this.itemTouched = true;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onItemKeyDown(event, listType) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowDown':
|
|
|
|
this.onArrowDownKey(event, listType);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'ArrowUp':
|
|
|
|
this.onArrowUpKey(event, listType);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Home':
|
|
|
|
this.onHomeKey(event, listType);
|
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'End':
|
|
|
|
this.onEndKey(event, listType);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Enter':
|
|
|
|
this.onEnterKey(event, listType);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Space':
|
|
|
|
this.onSpaceKey(event, listType);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'KeyA':
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
this.d_selection = [...this.modelValue];
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
}
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
default:
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onArrowDownKey(event, listType) {
|
|
|
|
const optionIndex = this.findNextOptionIndex(this.focusedOptionIndex, listType);
|
|
|
|
|
|
|
|
this.changeFocusedOptionIndex(optionIndex, listType);
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
this.onEnterKey(event, listType);
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
event.preventDefault();
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onArrowUpKey(event, listType) {
|
|
|
|
const optionIndex = this.findPrevOptionIndex(this.focusedOptionIndex, listType);
|
|
|
|
|
|
|
|
this.changeFocusedOptionIndex(optionIndex, listType);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
if (event.shiftKey) {
|
|
|
|
this.onEnterKey(event, listType);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onEnterKey(event, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
|
|
|
const focusedItem = DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id=${this.focusedOptionIndex}]`);
|
2022-12-08 11:04:25 +00:00
|
|
|
const matchedOptionIndex = [...items].findIndex((item) => item === focusedItem);
|
|
|
|
const listId = listType === 'sourceList' ? 0 : 1;
|
|
|
|
|
|
|
|
this.onItemClick(event, this.modelValue[listId][matchedOptionIndex], matchedOptionIndex, listId);
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onSpaceKey(event, listType) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
const listId = listType === 'sourceList' ? 0 : 1;
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
const selectedItemIndex = ObjectUtils.findIndexInList(this.d_selection[listId][0], [...this.modelValue[listId]]);
|
2023-06-02 15:43:30 +00:00
|
|
|
const focusedItem = DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id=${this.focusedOptionIndex}]`);
|
2022-12-08 11:04:25 +00:00
|
|
|
const matchedOptionIndex = [...items].findIndex((item) => item === focusedItem);
|
|
|
|
|
|
|
|
this.d_selection[listId] = [...this.modelValue[listId]].slice(Math.min(selectedItemIndex, matchedOptionIndex), Math.max(selectedItemIndex, matchedOptionIndex) + 1);
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
} else {
|
|
|
|
this.onEnterKey(event, listType);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onHomeKey(event, listType) {
|
|
|
|
if (event.ctrlKey && event.shiftKey) {
|
|
|
|
const listId = listType === 'sourceList' ? 0 : 1;
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
|
|
|
const focusedItem = DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id=${this.focusedOptionIndex}]`);
|
2022-12-08 11:04:25 +00:00
|
|
|
const matchedOptionIndex = [...items].findIndex((item) => item === focusedItem);
|
|
|
|
|
|
|
|
this.d_selection[listId] = [...this.modelValue[listId]].slice(0, matchedOptionIndex + 1);
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
} else {
|
|
|
|
this.changeFocusedOptionIndex(0, listType);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onEndKey(event, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
if (event.ctrlKey && event.shiftKey) {
|
|
|
|
const listId = listType === 'sourceList' ? 0 : 1;
|
2023-06-02 15:43:30 +00:00
|
|
|
const focusedItem = DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id=${this.focusedOptionIndex}]`);
|
2022-12-08 11:04:25 +00:00
|
|
|
const matchedOptionIndex = [...items].findIndex((item) => item === focusedItem);
|
|
|
|
|
|
|
|
this.d_selection[listId] = [...this.modelValue[listId]].slice(matchedOptionIndex, items.length);
|
|
|
|
this.$emit('update:selection', this.d_selection);
|
|
|
|
} else {
|
|
|
|
this.changeFocusedOptionIndex(items.length - 1, listType);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
findNextOptionIndex(index, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
const matchedOptionIndex = [...items].findIndex((link) => link.id === index);
|
|
|
|
|
|
|
|
return matchedOptionIndex > -1 ? matchedOptionIndex + 1 : 0;
|
|
|
|
},
|
|
|
|
findPrevOptionIndex(index, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
const matchedOptionIndex = [...items].findIndex((link) => link.id === index);
|
|
|
|
|
|
|
|
return matchedOptionIndex > -1 ? matchedOptionIndex - 1 : 0;
|
|
|
|
},
|
|
|
|
changeFocusedOptionIndex(index, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const items = DomHandler.find(this.$refs[listType].$el, '[data-pc-section="item"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
let order = index >= items.length ? items.length - 1 : index < 0 ? 0 : index;
|
|
|
|
|
|
|
|
this.focusedOptionIndex = items[order].getAttribute('id');
|
|
|
|
this.scrollInView(items[order].getAttribute('id'), listType);
|
|
|
|
},
|
|
|
|
scrollInView(id, listType) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const element = DomHandler.findSingle(this.$refs[listType].$el, `[data-pc-section="item"][id="${id}"]`);
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'start' });
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
updateListScroll(listElement) {
|
2023-06-02 15:43:30 +00:00
|
|
|
const listItems = DomHandler.find(listElement, '[data-pc-section="item"][data-p-highlight="true"]');
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (listItems && listItems.length) {
|
2022-09-14 11:26:01 +00:00
|
|
|
switch (this.reorderDirection) {
|
2022-09-06 12:03:37 +00:00
|
|
|
case 'up':
|
|
|
|
DomHandler.scrollInView(listElement, listItems[0]);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
case 'top':
|
|
|
|
listElement.scrollTop = 0;
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
case 'down':
|
|
|
|
DomHandler.scrollInView(listElement, listItems[listItems.length - 1]);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
case 'bottom':
|
|
|
|
listElement.scrollTop = listElement.scrollHeight;
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
default:
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-04-18 13:55:04 +00:00
|
|
|
initMedia() {
|
|
|
|
this.media = window.matchMedia(`(max-width: ${this.breakpoint})`);
|
|
|
|
this.viewChanged = this.media.matches;
|
|
|
|
this.bindMediaChangeListener();
|
|
|
|
},
|
|
|
|
destroyMedia() {
|
|
|
|
this.unbindMediaChangeListener();
|
|
|
|
},
|
|
|
|
bindMediaChangeListener() {
|
|
|
|
if (this.media && !this.mediaChangeListener) {
|
|
|
|
this.mediaChangeListener = (event) => {
|
|
|
|
this.viewChanged = event.matches;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.media.addEventListener('change', this.mediaChangeListener);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unbindMediaChangeListener() {
|
|
|
|
if (this.media && this.mediaChangeListener) {
|
|
|
|
this.media.removeEventListener('change', this.mediaChangeListener);
|
|
|
|
this.mediaChangeListener = null;
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
createStyle() {
|
2023-06-05 11:24:13 +00:00
|
|
|
if (!this.styleElement && !this.isUnstyled) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$el.setAttribute(this.attributeSelector, '');
|
2022-09-14 11:26:01 +00:00
|
|
|
this.styleElement = document.createElement('style');
|
|
|
|
this.styleElement.type = 'text/css';
|
|
|
|
document.head.appendChild(this.styleElement);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
let innerHTML = `
|
|
|
|
@media screen and (max-width: ${this.breakpoint}) {
|
|
|
|
.p-picklist[${this.attributeSelector}] {
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-picklist[${this.attributeSelector}] .p-picklist-buttons {
|
|
|
|
padding: var(--content-padding);
|
|
|
|
flex-direction: row;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-picklist[${this.attributeSelector}] .p-picklist-buttons .p-button {
|
|
|
|
margin-right: var(--inline-spacing);
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-picklist[${this.attributeSelector}] .p-picklist-buttons .p-button:last-child {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
this.styleElement.innerHTML = innerHTML;
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
destroyStyle() {
|
|
|
|
if (this.styleElement) {
|
|
|
|
document.head.removeChild(this.styleElement);
|
|
|
|
this.styleElement = null;
|
|
|
|
}
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
moveDisabled(index) {
|
|
|
|
if (!this.d_selection[index] || !this.d_selection[index].length) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
moveAllDisabled(list) {
|
|
|
|
return ObjectUtils.isEmpty(this[list]);
|
|
|
|
},
|
|
|
|
moveSourceDisabled() {
|
|
|
|
return ObjectUtils.isEmpty(this.targetList);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-12-08 11:04:25 +00:00
|
|
|
idSource() {
|
2023-01-19 04:01:03 +00:00
|
|
|
return `${this.id}_source`;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
idTarget() {
|
2023-01-19 04:01:03 +00:00
|
|
|
return `${this.id}_target`;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
focusedOptionId() {
|
|
|
|
return this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : null;
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
sourceList() {
|
|
|
|
return this.modelValue && this.modelValue[0] ? this.modelValue[0] : null;
|
|
|
|
},
|
|
|
|
targetList() {
|
|
|
|
return this.modelValue && this.modelValue[1] ? this.modelValue[1] : null;
|
|
|
|
},
|
|
|
|
attributeSelector() {
|
|
|
|
return UniqueComponentId();
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
moveUpAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveUp : undefined;
|
|
|
|
},
|
|
|
|
moveTopAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveTop : undefined;
|
|
|
|
},
|
|
|
|
moveDownAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveDown : undefined;
|
|
|
|
},
|
|
|
|
moveBottomAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveBottom : undefined;
|
|
|
|
},
|
|
|
|
moveToTargetAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveToTarget : undefined;
|
|
|
|
},
|
|
|
|
moveAllToTargetAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveAllToTarget : undefined;
|
|
|
|
},
|
|
|
|
moveToSourceAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveToSource : undefined;
|
|
|
|
},
|
|
|
|
moveAllToSourceAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveAllToSource : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2023-04-07 06:47:43 +00:00
|
|
|
PLButton: Button,
|
|
|
|
AngleRightIcon: AngleRightIcon,
|
|
|
|
AngleLeftIcon: AngleLeftIcon,
|
|
|
|
AngleDownIcon: AngleDownIcon,
|
|
|
|
AngleUpIcon: AngleUpIcon,
|
|
|
|
AngleDoubleRightIcon: AngleDoubleRightIcon,
|
|
|
|
AngleDoubleLeftIcon: AngleDoubleLeftIcon,
|
|
|
|
AngleDoubleDownIcon: AngleDoubleDownIcon,
|
|
|
|
AngleDoubleUpIcon: AngleDoubleUpIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|