UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 9.73 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/hooks"),r=require("primereact/api"),n=require("primereact/utils"),l=require("primereact/button"),i=require("primereact/ripple");function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=a(e);function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},u.apply(this,arguments)}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e){if(Array.isArray(e))return c(e)}function d(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function f(e,t){if(e){if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?c(e,t):void 0}}function p(){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 m(e){return s(e)||d(e)||f(e)||p()}function v(e){if(Array.isArray(e))return e}function g(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,l,i=[],a=!0,o=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){o=!0,l=e}finally{try{a||null==r.return||r.return()}finally{if(o)throw l}}return i}}function y(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(e,t){return v(e)||g(e,t)||f(e,t)||y()}var b=o.memo((function(e){return o.createElement("div",{className:"p-orderlist-controls"},o.createElement(l.Button,{type:"button",icon:"pi pi-angle-up",onClick:function(t){if(e.selection){for(var r=m(e.value),l=0;l<e.selection.length;l++){var i=n.ObjectUtils.findIndexInList(e.selection[l],r,e.dataKey);if(0===i)break;var a=r[i-1];r[i-1]=r[i],r[i]=a}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"up"})}}}),o.createElement(l.Button,{type:"button",icon:"pi pi-angle-double-up",onClick:function(t){if(e.selection){for(var r=m(e.value),l=0;l<e.selection.length;l++){var i=n.ObjectUtils.findIndexInList(e.selection[l],r,e.dataKey);if(0===i)break;var a=r.splice(i,1)[0];r.unshift(a)}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"top"})}}}),o.createElement(l.Button,{type:"button",icon:"pi pi-angle-down",onClick:function(t){if(e.selection){for(var r=m(e.value),l=e.selection.length-1;l>=0;l--){var i=n.ObjectUtils.findIndexInList(e.selection[l],r,e.dataKey);if(i===r.length-1)break;var a=r[i+1];r[i+1]=r[i],r[i]=a}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"down"})}}}),o.createElement(l.Button,{type:"button",icon:"pi pi-angle-double-down",onClick:function(t){if(e.selection){for(var r=m(e.value),l=e.selection.length-1;l>=0;l--){var i=n.ObjectUtils.findIndexInList(e.selection[l],r,e.dataKey);if(i===r.length-1)break;var a=r.splice(i,1)[0];r.push(a)}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"bottom"})}}}))}));b.displayName="OrderListControls";var E=o.memo((function(e){var t,r=o.useRef(null),l=o.useRef(null),a=o.useRef(null),u=o.useRef(null),c={filter:function(t){return e.onFilterInputChange(t)},reset:function(){return e.resetFilter()}},s=function(t){return-1!==n.ObjectUtils.findIndexInList(t,e.selection,e.dataKey)},d=function(e,t){l.current!==t&&l.current+1!==t&&(a.current=t,n.DomHandler.addClass(e.target,"p-orderlist-droppoint-highlight"),e.preventDefault())},f=function(e){a.current=null,n.DomHandler.removeClass(e.target,"p-orderlist-droppoint-highlight")},p=function(t){var r=l.current>a.current?a.current:0===a.current?0:a.current-1,i=m(e.value);n.ObjectUtils.reorderArray(i,l.current,r),a.current=null,n.DomHandler.removeClass(t.target,"p-orderlist-droppoint-highlight"),e.onChange&&e.onChange({originalEvent:t,value:i})},v=function(e){r.current=!1},g=function(e){if(r.current){var t=u.current.getBoundingClientRect().top+n.DomHandler.getWindowScrollTop(),l=t+u.current.clientHeight-e.pageY,i=e.pageY-t;l<25&&l>0?u.current.scrollTop+=15:i<25&&i>0&&(u.current.scrollTop-=15)}},y=function(e){13===e.which&&e.preventDefault()},h=function(e,t){return o.createElement("li",{key:t,className:"p-orderlist-droppoint",onDragOver:function(t){return d(t,e+1)},onDragLeave:f,onDrop:p})},b=e.header?o.createElement("div",{className:"p-orderlist-header"},e.header):null,E=function(){if(e.filter){var t=o.createElement("div",{className:"p-orderlist-filter"},o.createElement("input",{type:"text",value:e.filterValue,onChange:e.onFilter,onKeyDown:y,placeholder:e.placeholder,className:"p-orderlist-filter-input p-inputtext p-component"}),o.createElement("span",{className:"p-orderlist-filter-icon pi pi-search"}));if(e.filterTemplate)t=n.ObjectUtils.getJSXElement(e.filterTemplate,{className:"p-orderlist-filter",inputProps:{inputClassName:"p-orderlist-filter-input p-inputtext p-component",onChange:e.onFilter,onKeyDown:y},filterOptions:c,iconClassName:"p-orderlist-filter-icon pi pi-search",element:t,props:e});return o.createElement("div",{className:"p-orderlist-filter-container"},t)}return null}(),I=(t=e.value?e.value.map((function(t,a){var u=e.itemTemplate?e.itemTemplate(t):t,c=n.classNames("p-orderlist-item",{"p-highlight":s(t)},e.className),d=JSON.stringify(t);if(e.dragdrop){var f=[h(a,d+"_droppoint"),o.createElement("li",{key:d,className:c,onClick:function(r){return e.onItemClick({originalEvent:r,value:t,index:a})},onKeyDown:function(r){return e.onItemKeyDown({originalEvent:r,value:t,index:a})},role:"option","aria-selected":s(t),draggable:"true",onDragStart:function(t){return n=t,i=a,r.current=!0,l.current=i,void(e.dragdropScope&&n.dataTransfer.setData("text","orderlist"));var n,i},onDragEnd:v,tabIndex:e.tabIndex},u,o.createElement(i.Ripple,null))];return a===e.value.length-1&&f.push(h(t,a)),f}return o.createElement("li",{key:d,className:c,role:"option","aria-selected":s(t),onClick:function(r){return e.onItemClick({originalEvent:r,value:t,index:a})},onKeyDown:function(r){return e.onItemKeyDown({originalEvent:r,value:t,index:a})},tabIndex:e.tabIndex},u)})):null,o.createElement("ul",{ref:u,className:"p-orderlist-list",style:e.listStyle,onDragOver:g,role:"listbox","aria-multiselectable":!0},t));return o.createElement("div",{className:"p-orderlist-list-container"},b,E,I)}));E.displayName="OrderListSubList";var I=o.memo(o.forwardRef((function(e,l){var i=h(o.useState([]),2),a=i[0],c=i[1],s=h(o.useState(""),2),d=s[0],f=s[1],p=n.ObjectUtils.isNotEmpty(d),v=o.useRef(null),g=o.useRef(null),y=function(t){var r,l=t.originalEvent.metaKey||t.originalEvent.ctrlKey,i=n.ObjectUtils.findIndexInList(t.value,a,e.dataKey);r=-1!==i?l?a.filter((function(e,t){return t!==i})):[t.value]:l?[].concat(m(a),[t.value]):[t.value],c(r)},O=function e(t){var r=t.nextElementSibling;return r?n.DomHandler.hasClass(r,"p-orderlist-item")?r:e(r):null},C=function e(t){var r=t.previousElementSibling;return r?n.DomHandler.hasClass(r,"p-orderlist-item")?r:e(r):null},D=function(){var e=n.DomHandler.findSingle(v.current,".p-orderlist-list"),t=n.DomHandler.find(e,".p-orderlist-item.p-highlight");if(t&&t.length)switch(g.current){case"up":n.DomHandler.scrollInView(e,t[0]);break;case"top":e.scrollTop=0;break;case"down":n.DomHandler.scrollInView(e,t[t.length-1]);break;case"bottom":setTimeout((function(){return e.scrollTop=e.scrollHeight}),100)}};o.useImperativeHandle(l,(function(){return{props:e,getElement:function(){return v.current}}})),t.useUpdateEffect((function(){g.current&&(D(),g.current=null)}));var w=n.ObjectUtils.findDiffKeys(e,I.defaultProps),x=n.classNames("p-orderlist p-component",e.className),N=function(){if(p){var t=d.trim().toLocaleLowerCase(e.filterLocale),n=e.filterBy?e.filterBy.split(","):[];return r.FilterService.filter(e.value,n,t,e.filterMatchMode,e.filterLocale)}return e.value}();return o.createElement("div",u({ref:v,id:e.id,className:x,style:e.style},w),o.createElement(b,{value:N,selection:a,onReorder:function(t){e.onChange&&e.onChange({event:t.originalEvent,value:t.value}),g.current=t.direction},dataKey:e.dataKey}),o.createElement(E,{value:N,selection:a,onItemClick:y,onItemKeyDown:function(e){var t=e.originalEvent,r=t.currentTarget;switch(t.which){case 40:var n=O(r);n&&n.focus(),t.preventDefault();break;case 38:var l=C(r);l&&l.focus(),t.preventDefault();break;case 13:y(e),t.preventDefault()}},onFilterInputChange:function(t){var r=t.target.value;f(r),e.onFilter&&e.onFilter({originalEvent:t,filter:r})},itemTemplate:e.itemTemplate,filter:e.filter,onFilter:function(t){var r=t.target.value;f(r),e.onFilter&&e.onFilter({originalEvent:t,value:r})},resetFilter:function(){f(""),e.onFilter&&e.onFilter({filter:""})},filterTemplate:e.filterTemplate,header:e.header,listStyle:e.listStyle,dataKey:e.dataKey,dragdrop:e.dragdrop,onChange:e.onChange,tabIndex:e.tabIndex}))})));I.displayName="OrderList",I.defaultProps={__TYPE:"OrderList",id:null,value:null,header:null,style:null,className:null,listStyle:null,dragdrop:!1,tabIndex:0,dataKey:null,onChange:null,itemTemplate:null,filter:!1,filterBy:null,filterMatchMode:"contains",filterLocale:void 0,filterPlaceholder:null,filterTemplate:null,onFilter:null},exports.OrderList=I;