primevue
Version:
PrimeVue is a premium UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, wh
526 lines (520 loc) • 21.1 kB
JavaScript
import AngleDoubleDown from '@primeicons/vue/angle-double-down';
import AngleDoubleUp from '@primeicons/vue/angle-double-up';
import AngleDown from '@primeicons/vue/angle-down';
import AngleUp from '@primeicons/vue/angle-up';
import { setAttribute } from '@primeuix/utils/dom';
import { findIndexInList } from '@primeuix/utils/object';
import Button from 'primevue/button';
import Listbox from 'primevue/listbox';
import Ripple from 'primevue/ripple';
import BaseComponent from '@primevue/core/basecomponent';
import OrderListStyle from 'primevue/orderlist/style';
import { resolveComponent, openBlock, createElementBlock, mergeProps, createElementVNode, renderSlot, createVNode, withCtx, createSlots } from 'vue';
var script$1 = {
name: 'BaseOrderList',
"extends": BaseComponent,
props: {
modelValue: {
type: Array,
"default": null
},
selection: {
type: Array,
"default": null
},
dataKey: {
type: String,
"default": null
},
listStyle: {
type: null,
"default": null
},
metaKeySelection: {
type: Boolean,
"default": false
},
autoOptionFocus: {
type: Boolean,
"default": true
},
focusOnHover: {
type: Boolean,
"default": true
},
responsive: {
type: Boolean,
"default": true
},
breakpoint: {
type: String,
"default": '960px'
},
striped: {
type: Boolean,
"default": false
},
scrollHeight: {
type: String,
"default": '14rem'
},
filter: Boolean,
filterPlaceholder: String,
filterLocale: String,
filterMatchMode: {
type: String,
"default": 'contains'
},
filterFields: {
type: Array,
"default": null
},
filterMessage: {
type: String,
"default": null
},
emptyFilterMessage: {
type: String,
"default": null
},
emptyMessage: {
type: String,
"default": null
},
buttonProps: {
type: Object,
"default": function _default() {
return {
severity: 'secondary',
iconOnly: true
};
}
},
moveUpButtonProps: {
type: null,
"default": null
},
moveTopButtonProps: {
type: null,
"default": null
},
moveDownButtonProps: {
type: null,
"default": null
},
moveBottomButtonProps: {
type: null,
"default": null
},
tabindex: {
type: Number,
"default": 0
},
disabled: {
type: Boolean,
"default": false
},
ariaLabelledby: {
type: String,
"default": null
},
ariaLabel: {
type: String,
"default": null
}
},
style: OrderListStyle,
provide: function provide() {
return {
$pcOrderList: this,
$parentInstance: this
};
}
};
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var script = {
name: 'OrderList',
"extends": script$1,
inheritAttrs: false,
emits: ['update:modelValue', 'reorder', 'update:selection', 'selection-change', 'focus', 'blur', 'filter'],
itemTouched: false,
reorderDirection: null,
styleElement: null,
data: function data() {
return {
d_selection: this.selection
};
},
beforeUnmount: function beforeUnmount() {
this.destroyStyle();
},
updated: function updated() {
if (this.reorderDirection) {
this.updateListScroll();
this.reorderDirection = null;
}
},
mounted: function mounted() {
if (this.responsive) {
this.createStyle();
}
},
methods: {
updateSelection: function updateSelection(event) {
this.$emit('update:selection', this.d_selection);
this.$emit('selection-change', {
originalEvent: event,
value: this.d_selection
});
},
onChangeSelection: function onChangeSelection(params) {
this.d_selection = params.value;
this.updateSelection(params.event);
},
onListFocus: function onListFocus(event) {
this.$emit('focus', event);
},
onListBlur: function onListBlur(event) {
this.$emit('blur', event);
},
onFilter: function onFilter(event) {
this.$emit('filter', event);
},
onReorderUpdate: function onReorderUpdate(event, value) {
this.$emit('update:modelValue', value);
this.$emit('reorder', {
originalEvent: event,
value: value,
direction: this.reorderDirection
});
},
moveUp: function moveUp(event) {
if (this.d_selection) {
var value = _toConsumableArray(this.modelValue);
var sortedSelection = this.sortByIndexInList(this.d_selection, value);
var _iterator = _createForOfIteratorHelper(sortedSelection),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var selectedItem = _step.value;
var selectedItemIndex = findIndexInList(selectedItem, value);
if (selectedItemIndex > 0 && findIndexInList(value[selectedItemIndex - 1], this.d_selection) === -1) {
var movedItem = value[selectedItemIndex];
var temp = value[selectedItemIndex - 1];
value[selectedItemIndex - 1] = movedItem;
value[selectedItemIndex] = temp;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
this.reorderDirection = 'up';
this.onReorderUpdate(event, value);
}
},
moveTop: function moveTop(event) {
if (this.d_selection) {
var value = _toConsumableArray(this.modelValue);
var sortedSelection = this.sortByIndexInList(this.d_selection, value).reverse();
var _iterator2 = _createForOfIteratorHelper(sortedSelection),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var selectedItem = _step2.value;
var selectedItemIndex = findIndexInList(selectedItem, value);
if (selectedItemIndex !== 0) {
var movedItem = value.splice(selectedItemIndex, 1)[0];
value.unshift(movedItem);
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
this.reorderDirection = 'top';
this.onReorderUpdate(event, value);
}
},
moveDown: function moveDown(event) {
if (this.d_selection) {
var value = _toConsumableArray(this.modelValue);
var sortedSelection = this.sortByIndexInList(this.d_selection, value).reverse();
var _iterator3 = _createForOfIteratorHelper(sortedSelection),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var selectedItem = _step3.value;
var selectedItemIndex = findIndexInList(selectedItem, value);
if (selectedItemIndex < value.length - 1 && findIndexInList(value[selectedItemIndex + 1], this.d_selection) === -1) {
var movedItem = value[selectedItemIndex];
var temp = value[selectedItemIndex + 1];
value[selectedItemIndex + 1] = movedItem;
value[selectedItemIndex] = temp;
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
this.reorderDirection = 'down';
this.onReorderUpdate(event, value);
}
},
moveBottom: function moveBottom(event) {
if (this.d_selection) {
var value = _toConsumableArray(this.modelValue);
var sortedSelection = this.sortByIndexInList(this.d_selection, value);
var _iterator4 = _createForOfIteratorHelper(sortedSelection),
_step4;
try {
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
var selectedItem = _step4.value;
var selectedItemIndex = findIndexInList(selectedItem, value);
if (selectedItemIndex !== value.length - 1) {
var movedItem = value.splice(selectedItemIndex, 1)[0];
value.push(movedItem);
}
}
} catch (err) {
_iterator4.e(err);
} finally {
_iterator4.f();
}
this.reorderDirection = 'bottom';
this.onReorderUpdate(event, value);
}
},
sortByIndexInList: function sortByIndexInList(items, list) {
return _toConsumableArray(items).sort(function (a, b) {
return findIndexInList(a, list) - findIndexInList(b, list);
});
},
updateListScroll: function updateListScroll() {
var _this = this;
if (!this.$refs.listbox || !this.d_selection || !this.d_selection.length) {
return;
}
var indexes = this.d_selection.map(function (item) {
return findIndexInList(item, _this.modelValue);
});
var targetIndex = this.reorderDirection === 'up' || this.reorderDirection === 'top' ? Math.min.apply(Math, _toConsumableArray(indexes)) : Math.max.apply(Math, _toConsumableArray(indexes));
this.$refs.listbox.scrollInView(targetIndex);
},
createStyle: function createStyle() {
if (!this.styleElement && !this.isUnstyled) {
var _this$$primevue;
this.styleElement = document.createElement('style');
this.styleElement.type = 'text/css';
setAttribute(this.styleElement, 'nonce', (_this$$primevue = this.$primevue) === null || _this$$primevue === void 0 || (_this$$primevue = _this$$primevue.config) === null || _this$$primevue === void 0 || (_this$$primevue = _this$$primevue.csp) === null || _this$$primevue === void 0 ? void 0 : _this$$primevue.nonce);
document.head.appendChild(this.styleElement);
var innerHTML = "\n@media screen and (max-width: ".concat(this.breakpoint, ") {\n .p-orderlist[").concat(this.$attrSelector, "] {\n flex-direction: column;\n }\n\n .p-orderlist[").concat(this.$attrSelector, "] .p-orderlist-controls {\n flex-direction: row;\n }\n}\n");
this.styleElement.innerHTML = innerHTML;
}
},
destroyStyle: function destroyStyle() {
if (this.styleElement) {
document.head.removeChild(this.styleElement);
this.styleElement = null;
}
},
moveDisabled: function moveDisabled() {
return this.disabled ? true : !this.d_selection || !this.d_selection.length ? true : false;
}
},
computed: {
moveUpAriaLabel: function moveUpAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveUp : undefined;
},
moveTopAriaLabel: function moveTopAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveTop : undefined;
},
moveDownAriaLabel: function moveDownAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveDown : undefined;
},
moveBottomAriaLabel: function moveBottomAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.moveBottom : undefined;
}
},
components: {
Listbox: Listbox,
Button: Button,
AngleUp: AngleUp,
AngleDown: AngleDown,
AngleDoubleUp: AngleDoubleUp,
AngleDoubleDown: AngleDoubleDown
},
directives: {
ripple: Ripple
}
};
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function render(_ctx, _cache, $props, $setup, $data, $options) {
var _component_AngleUp = resolveComponent("AngleUp");
var _component_Button = resolveComponent("Button");
var _component_AngleDoubleUp = resolveComponent("AngleDoubleUp");
var _component_AngleDown = resolveComponent("AngleDown");
var _component_AngleDoubleDown = resolveComponent("AngleDoubleDown");
var _component_Listbox = resolveComponent("Listbox");
return openBlock(), createElementBlock("div", mergeProps({
"class": _ctx.cx('root')
}, _ctx.ptmi('root')), [createElementVNode("div", mergeProps({
"class": _ctx.cx('controls')
}, _ctx.ptm('controls')), [renderSlot(_ctx.$slots, "controlsstart"), createVNode(_component_Button, mergeProps({
onClick: $options.moveUp,
"aria-label": $options.moveUpAriaLabel,
disabled: $options.moveDisabled()
}, _objectSpread(_objectSpread({}, _ctx.buttonProps), _ctx.moveUpButtonProps), {
pt: _ctx.ptm('pcMoveUpButton'),
unstyled: _ctx.unstyled
}), {
"default": withCtx(function () {
return [renderSlot(_ctx.$slots, "moveupicon", {}, function () {
return [createVNode(_component_AngleUp, mergeProps(_ctx.ptm('pcMoveUpButton')['icon'], {
"data-pc-section": "moveupicon"
}), null, 16)];
})];
}),
_: 3
}, 16, ["onClick", "aria-label", "disabled", "pt", "unstyled"]), createVNode(_component_Button, mergeProps({
onClick: $options.moveTop,
"aria-label": $options.moveTopAriaLabel,
disabled: $options.moveDisabled()
}, _objectSpread(_objectSpread({}, _ctx.buttonProps), _ctx.moveTopButtonProps), {
pt: _ctx.ptm('pcMoveTopButton'),
unstyled: _ctx.unstyled
}), {
"default": withCtx(function () {
return [renderSlot(_ctx.$slots, "movetopicon", {}, function () {
return [createVNode(_component_AngleDoubleUp, mergeProps(_ctx.ptm('pcMoveTopButton')['icon'], {
"data-pc-section": "movetopicon"
}), null, 16)];
})];
}),
_: 3
}, 16, ["onClick", "aria-label", "disabled", "pt", "unstyled"]), createVNode(_component_Button, mergeProps({
onClick: $options.moveDown,
"aria-label": $options.moveDownAriaLabel,
disabled: $options.moveDisabled()
}, _objectSpread(_objectSpread({}, _ctx.buttonProps), _ctx.moveDownButtonProps), {
pt: _ctx.ptm('pcMoveDownButton'),
unstyled: _ctx.unstyled
}), {
"default": withCtx(function () {
return [renderSlot(_ctx.$slots, "movedownicon", {}, function () {
return [createVNode(_component_AngleDown, mergeProps(_ctx.ptm('pcMoveDownButton')['icon'], {
"data-pc-section": "movedownicon"
}), null, 16)];
})];
}),
_: 3
}, 16, ["onClick", "aria-label", "disabled", "pt", "unstyled"]), createVNode(_component_Button, mergeProps({
onClick: $options.moveBottom,
"aria-label": $options.moveBottomAriaLabel,
disabled: $options.moveDisabled()
}, _objectSpread(_objectSpread({}, _ctx.buttonProps), _ctx.moveBottomButtonProps), {
pt: _ctx.ptm('pcMoveBottomButton'),
unstyled: _ctx.unstyled
}), {
"default": withCtx(function () {
return [renderSlot(_ctx.$slots, "movebottomicon", {}, function () {
return [createVNode(_component_AngleDoubleDown, mergeProps(_ctx.ptm('pcMoveBottomButton')['icon'], {
"data-pc-section": "movebottomicon"
}), null, 16)];
})];
}),
_: 3
}, 16, ["onClick", "aria-label", "disabled", "pt", "unstyled"]), renderSlot(_ctx.$slots, "controlsend")], 16), createVNode(_component_Listbox, {
ref: "listbox",
id: _ctx.$id,
modelValue: $data.d_selection,
options: _ctx.modelValue,
multiple: "",
metaKeySelection: _ctx.metaKeySelection,
listStyle: _ctx.listStyle,
scrollHeight: _ctx.scrollHeight,
tabindex: _ctx.tabindex,
dataKey: _ctx.dataKey,
autoOptionFocus: _ctx.autoOptionFocus,
focusOnHover: _ctx.focusOnHover,
striped: _ctx.striped,
disabled: _ctx.disabled,
filter: _ctx.filter,
filterPlaceholder: _ctx.filterPlaceholder,
filterLocale: _ctx.filterLocale,
filterMatchMode: _ctx.filterMatchMode,
filterFields: _ctx.filterFields,
filterMessage: _ctx.filterMessage,
emptyFilterMessage: _ctx.emptyFilterMessage,
emptyMessage: _ctx.emptyMessage,
ariaLabel: _ctx.ariaLabel,
ariaLabelledby: _ctx.ariaLabelledby,
onFocus: $options.onListFocus,
onBlur: $options.onListBlur,
onChange: $options.onChangeSelection,
onFilter: $options.onFilter,
pt: _ctx.ptm('pcListbox'),
unstyled: _ctx.unstyled
}, createSlots({
option: withCtx(function (_ref) {
var option = _ref.option,
selected = _ref.selected,
index = _ref.index;
return [renderSlot(_ctx.$slots, "option", {
item: option,
option: option,
selected: selected,
index: index
})];
}),
_: 2
}, [_ctx.$slots.header ? {
name: "header",
fn: withCtx(function () {
return [renderSlot(_ctx.$slots, "header")];
}),
key: "0"
} : undefined, _ctx.$slots.filtericon ? {
name: "filtericon",
fn: withCtx(function () {
return [renderSlot(_ctx.$slots, "filtericon")];
}),
key: "1"
} : undefined, _ctx.$slots.empty ? {
name: "empty",
fn: withCtx(function () {
return [renderSlot(_ctx.$slots, "empty")];
}),
key: "2"
} : undefined, _ctx.$slots.emptyfilter ? {
name: "emptyfilter",
fn: withCtx(function () {
return [renderSlot(_ctx.$slots, "emptyfilter")];
}),
key: "3"
} : undefined, _ctx.$slots.footer ? {
name: "footer",
fn: withCtx(function () {
return [renderSlot(_ctx.$slots, "footer", {
value: _ctx.modelValue
})];
}),
key: "4"
} : undefined]), 1032, ["id", "modelValue", "options", "metaKeySelection", "listStyle", "scrollHeight", "tabindex", "dataKey", "autoOptionFocus", "focusOnHover", "striped", "disabled", "filter", "filterPlaceholder", "filterLocale", "filterMatchMode", "filterFields", "filterMessage", "emptyFilterMessage", "emptyMessage", "ariaLabel", "ariaLabelledby", "onFocus", "onBlur", "onChange", "onFilter", "pt", "unstyled"])], 16);
}
script.render = render;
export { script as default };