primereact
Version:
PrimeReact is an open source UI library for React 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 Prime
2 lines (1 loc) • 11 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),r=require("primereact/hooks"),n=require("primereact/utils"),l=require("primereact/button"),i=require("primereact/ripple");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}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 u=a(e),c=o(t);function s(){return s=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},s.apply(this,arguments)}function d(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 p(e){if(Array.isArray(e))return d(e)}function f(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function m(e,t){if(e){if("string"==typeof e)return d(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)?d(e,t):void 0}}function v(){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 g(e){return p(e)||f(e)||m(e)||v()}function h(e){if(Array.isArray(e))return e}function y(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,l,i,o,a=[],u=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(e){c=!0,l=e}finally{try{if(!u&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(c)throw l}}return a}}function b(){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 E(e,t){return h(e)||y(e,t)||m(e,t)||b()}var I={defaultProps:{__TYPE:"OrderList",id:null,value:null,header:null,style:null,className:null,listStyle:null,dragdrop:!1,tabIndex:0,dataKey:null,breakpoint:"960px",onChange:null,itemTemplate:null,filter:!1,filterBy:null,filterMatchMode:"contains",filterLocale:void 0,filterPlaceholder:null,filterTemplate:null,onFilter:null,children:void 0},getProps:function(e){return n.ObjectUtils.getMergedProps(e,I.defaultProps)},getOtherProps:function(e){return n.ObjectUtils.getDiffProps(e,I.defaultProps)}},O=u.memo((function(e){return u.createElement("div",{className:"p-orderlist-controls"},u.createElement(l.Button,{type:"button",icon:"pi pi-angle-up",onClick:function(t){if(e.selection){for(var r=g(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 o=r[i-1];r[i-1]=r[i],r[i]=o}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"up"})}}}),u.createElement(l.Button,{type:"button",icon:"pi pi-angle-double-up",onClick:function(t){if(e.selection){for(var r=g(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 o=r.splice(i,1)[0];r.unshift(o)}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"top"})}}}),u.createElement(l.Button,{type:"button",icon:"pi pi-angle-down",onClick:function(t){if(e.selection){for(var r=g(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 o=r[i+1];r[i+1]=r[i],r[i]=o}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"down"})}}}),u.createElement(l.Button,{type:"button",icon:"pi pi-angle-double-down",onClick:function(t){if(e.selection){for(var r=g(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 o=r.splice(i,1)[0];r.push(o)}e.onReorder&&e.onReorder({originalEvent:t,value:r,direction:"bottom"})}}}))}));O.displayName="OrderListControls";var D=u.memo((function(e){var t,r=u.useRef(null),l=u.useRef(null),o=u.useRef(null),a=u.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&&(o.current=t,n.DomHandler.addClass(e.target,"p-orderlist-droppoint-highlight"),e.preventDefault())},p=function(e){o.current=null,n.DomHandler.removeClass(e.target,"p-orderlist-droppoint-highlight")},f=function(t){var r=l.current>o.current?o.current:0===o.current?0:o.current-1,i=g(e.value);n.ObjectUtils.reorderArray(i,l.current,r),o.current=null,n.DomHandler.removeClass(t.target,"p-orderlist-droppoint-highlight"),e.onChange&&e.onChange({originalEvent:t,value:i})},m=function(e){r.current=!1},v=function(e){if(r.current){var t=a.current.getBoundingClientRect().top+n.DomHandler.getWindowScrollTop(),l=t+a.current.clientHeight-e.pageY,i=e.pageY-t;l<25&&l>0?a.current.scrollTop+=15:i<25&&i>0&&(a.current.scrollTop-=15)}},h=function(e){13===e.which&&e.preventDefault()},y=function(e,t){return u.createElement("li",{key:t,className:"p-orderlist-droppoint",onDragOver:function(t){return d(t,e+1)},onDragLeave:p,onDrop:f})},b=e.header?u.createElement("div",{className:"p-orderlist-header"},e.header):null,E=function(){if(e.filter){var t=u.createElement("div",{className:"p-orderlist-filter"},u.createElement("input",{type:"text",value:e.filterValue,onChange:e.onFilter,onKeyDown:h,placeholder:e.placeholder,className:"p-orderlist-filter-input p-inputtext p-component"}),u.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:h},filterOptions:c,iconClassName:"p-orderlist-filter-icon pi pi-search",element:t,props:e});return u.createElement("div",{className:"p-orderlist-filter-container"},t)}return null}(),I=(t=e.value?e.value.map((function(t,o){var a=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 p=[];return 0===o&&p.push(y(t,o)),p.push(u.createElement("li",{key:d,className:c,onClick:function(r){return e.onItemClick({originalEvent:r,value:t,index:o})},onKeyDown:function(r){return e.onItemKeyDown({originalEvent:r,value:t,index:o})},role:"option","aria-selected":s(t),draggable:"true",onDragStart:function(t){return n=t,i=o,r.current=!0,l.current=i,void(e.dragdropScope&&n.dataTransfer.setData("text","orderlist"));var n,i},onDragEnd:m,tabIndex:e.tabIndex},a,u.createElement(i.Ripple,null))),p.push(y(o,d+"_droppoint")),p}return u.createElement("li",{key:d,className:c,role:"option","aria-selected":s(t),onClick:function(r){return e.onItemClick({originalEvent:r,value:t,index:o})},onKeyDown:function(r){return e.onItemKeyDown({originalEvent:r,value:t,index:o})},tabIndex:e.tabIndex},a)})):null,u.createElement("ul",{ref:a,className:"p-orderlist-list",style:e.listStyle,onDragOver:v,role:"listbox","aria-multiselectable":!0},t));return u.createElement("div",{className:"p-orderlist-list-container"},b,E,I)}));D.displayName="OrderListSubList";var C=u.memo(u.forwardRef((function(e,l){var i=I.getProps(e),o=E(u.useState([]),2),a=o[0],d=o[1],p=E(u.useState(""),2),f=p[0],m=p[1],v=E(u.useState(null),2),h=v[0],y=v[1],b=n.ObjectUtils.isNotEmpty(f),C=u.useRef(null),w=u.useRef(null),x=u.useRef(null),j=function(e){var t,r=e.originalEvent.metaKey||e.originalEvent.ctrlKey,l=n.ObjectUtils.findIndexInList(e.value,a,i.dataKey);t=-1!==l?r?a.filter((function(e,t){return t!==l})):[e.value]:r?[].concat(g(a),[e.value]):[e.value],d(t)},S=function e(t){var r=t.nextElementSibling;return r?n.DomHandler.hasClass(r,"p-orderlist-item")?r:e(r):null},k=function e(t){var r=t.previousElementSibling;return r?n.DomHandler.hasClass(r,"p-orderlist-item")?r:e(r):null},N=function(){var e=n.DomHandler.findSingle(C.current,".p-orderlist-list"),t=n.DomHandler.find(e,".p-orderlist-item.p-highlight");if(t&&t.length)switch(x.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)}},T=function(){if(!w.current){w.current=n.DomHandler.createInlineStyle(c.default.nonce);var e="\n@media screen and (max-width: ".concat(i.breakpoint,") {\n .p-orderlist[").concat(h,"] {\n flex-direction: column;\n }\n\n .p-orderlist[").concat(h,"] .p-orderlist-controls {\n padding: var(--content-padding);\n flex-direction: row;\n }\n\n .p-orderlist[").concat(h,"] .p-orderlist-controls .p-button {\n margin-right: var(--inline-spacing);\n margin-bottom: 0;\n }\n\n .p-orderlist[").concat(h,"] .p-orderlist-controls .p-button:last-child {\n margin-right: 0;\n }\n}\n");w.current.innerHTML=e}};u.useImperativeHandle(l,(function(){return{props:i,getElement:function(){return C.current}}})),r.useMountEffect((function(){!h&&y(n.UniqueComponentId())})),r.useUpdateEffect((function(){return h&&(C.current.setAttribute(h,""),T()),function(){w.current=n.DomHandler.removeInlineStyle(w.current)}}),[h,i.breakpoint]),r.useUpdateEffect((function(){x.current&&(N(),x.current=null)}));var K=I.getOtherProps(i),L=n.classNames("p-orderlist p-component",i.className),R=function(){if(b){var e=f.trim().toLocaleLowerCase(i.filterLocale),r=i.filterBy?i.filterBy.split(","):[];return t.FilterService.filter(i.value,r,e,i.filterMatchMode,i.filterLocale)}return i.value}();return u.createElement("div",s({ref:C,id:i.id,className:L,style:i.style},K),u.createElement(O,{value:R,selection:a,onReorder:function(e){i.onChange&&i.onChange({event:e.originalEvent,value:e.value}),x.current=e.direction},dataKey:i.dataKey}),u.createElement(D,{value:R,selection:a,onItemClick:j,onItemKeyDown:function(e){var t=e.originalEvent,r=t.currentTarget;switch(t.which){case 40:var n=S(r);n&&n.focus(),t.preventDefault();break;case 38:var l=k(r);l&&l.focus(),t.preventDefault();break;case 13:j(e),t.preventDefault()}},onFilterInputChange:function(e){var t=e.target.value;m(t),i.onFilter&&i.onFilter({originalEvent:e,filter:t})},itemTemplate:i.itemTemplate,filter:i.filter,onFilter:function(e){var t=e.target.value;m(t),i.onFilter&&i.onFilter({originalEvent:e,value:t})},resetFilter:function(){m(""),i.onFilter&&i.onFilter({filter:""})},filterTemplate:i.filterTemplate,header:i.header,listStyle:i.listStyle,dataKey:i.dataKey,dragdrop:i.dragdrop,onChange:i.onChange,tabIndex:i.tabIndex}))})));C.displayName="OrderList",exports.OrderList=C;
;