UNPKG

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) 32.9 kB
import*as e from"react";import t,{ariaLabel as n,PrimeReactContext as o,FilterService as r}from"primereact/api";import{ComponentBase as a,useHandleStyle as i}from"primereact/componentbase";import{useMergeProps as l,useMatchMedia as c,useUpdateEffect as s}from"primereact/hooks";import{classNames as u,ObjectUtils as p,IconUtils as m,UniqueComponentId as d,DomHandler as f}from"primereact/utils";import{Button as v}from"primereact/button";import{AngleDoubleDownIcon as g}from"primereact/icons/angledoubledown";import{AngleDoubleUpIcon as h}from"primereact/icons/angledoubleup";import{AngleDownIcon as y}from"primereact/icons/angledown";import{AngleUpIcon as T}from"primereact/icons/angleup";import{SearchIcon as S}from"primereact/icons/search";import{Ripple as b}from"primereact/ripple";import{AngleDoubleLeftIcon as I}from"primereact/icons/angledoubleleft";import{AngleDoubleRightIcon as E}from"primereact/icons/angledoubleright";import{AngleLeftIcon as w}from"primereact/icons/angleleft";import{AngleRightIcon as N}from"primereact/icons/angleright";function A(e){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},A(e)}function k(e,t){if("object"!=A(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=A(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function C(e){var t=k(e,"string");return"symbol"==A(t)?t:t+""}function L(e,t,n){return(t=C(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function M(e){if(Array.isArray(e))return O(e)}function x(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function D(e,t){if(e){if("string"==typeof e)return O(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O(e,t):void 0}}function F(){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 P(e){return M(e)||x(e)||D(e)||F()}function _(e){if(Array.isArray(e))return e}function R(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,a,i,l=[],c=!0,s=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(o=a.call(n)).done)&&(l.push(o.value),l.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{if(!c&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(s)throw r}}return l}}function K(){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 B(e,t){return _(e)||R(e,t)||D(e,t)||K()}var j=a.extend({defaultProps:{__TYPE:"PickList",id:null,source:null,target:null,sourceHeader:null,targetHeader:null,style:null,className:null,sourceStyle:null,targetStyle:null,sourceSelection:null,targetSelection:null,showSourceControls:!0,showTargetControls:!0,metaKeySelection:!1,onFocus:null,onBlur:null,filter:!1,filterBy:null,filterMatchMode:"contains",targetFilterIcon:null,sourceFilterIcon:null,moveAllToSourceIcon:null,moveToSourceIcon:null,moveAllToTargetIcon:null,moveToTargetIcon:null,moveBottomIcon:null,moveUpIcon:null,moveTopIcon:null,moveDownIcon:null,filterLocale:void 0,sourceFilterValue:null,targetFilterValue:null,showSourceFilter:!0,showTargetFilter:!0,sourceFilterPlaceholder:null,targetFilterPlaceholder:null,sourceFilterTemplate:null,targetFilterTemplate:null,tabIndex:0,dataKey:null,autoOptionFocus:!0,focusOnHover:!0,breakpoint:"960px",itemTemplate:null,sourceItemTemplate:null,targetItemTemplate:null,onChange:null,onMoveToSource:null,onMoveAllToSource:null,onMoveToTarget:null,onMoveAllToTarget:null,onSourceSelectionChange:null,onTargetSelectionChange:null,onSourceFilterChange:null,onTargetFilterChange:null,children:void 0},css:{classes:{root:"p-picklist p-component",buttons:"p-picklist-buttons p-picklist-transfer-buttons",header:"p-picklist-header",filterIcon:"p-picklist-filter-icon",filter:"p-picklist-filter",filterInput:"p-picklist-filter-input p-inputtext p-component",filterContainer:"p-picklist-filter-container",list:"p-picklist-list",listWrapper:"p-picklist-list-wrapper",listSourceWrapper:"p-picklist-list-wrapper p-picklist-source-wrapper",listTargetWrapper:"p-picklist-list-wrapper p-picklist-target-wrapper",listSource:"p-picklist-list p-picklist-source",listTarget:"p-picklist-list p-picklist-target",item:function(e){return u("p-picklist-item",{"p-highlight":e.selected,"p-focus":e.focused})},sourceControls:"p-picklist-source-controls p-picklist-buttons",targetControls:"p-picklist-target-controls p-picklist-buttons"},styles:"\n@layer primereact {\n .p-picklist {\n display: flex;\n }\n\n .p-picklist-buttons {\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n\n .p-picklist-list-wrapper {\n flex: 1 1 50%;\n }\n\n .p-picklist-list {\n list-style-type: none;\n margin: 0;\n padding: 0;\n overflow: auto;\n min-height: 12rem;\n max-height: 24rem;\n }\n\n .p-picklist-item {\n cursor: pointer;\n overflow: hidden;\n position: relative;\n }\n\n .p-picklist-item .p-ink {\n pointer-events: none;\n }\n\n .p-picklist-filter {\n position: relative;\n }\n\n .p-picklist-filter-icon {\n position: absolute;\n top: 50%;\n margin-top: -.5rem;\n }\n\n .p-picklist-filter-input {\n width: 100%;\n }\n}\n"}}),H=e.memo(function(t){var o=l(),r=t.ptm,a=t.cx,i=t.unstyled,c=t.moveUpIcon||e.createElement(T,null),s=t.moveTopIcon||e.createElement(h,null),m=t.moveDownIcon||e.createElement(y,null),d=t.moveBottomIcon||e.createElement(g,null),f=!t.selection||!t.selection.length,S=o({className:u(t.className,a("controls"))},r("controls",{hostName:t.hostName}));return e.createElement("div",S,e.createElement(v,{disabled:f,type:"button",icon:c,onClick:function(e){var n=t.selection;if(n&&n.length){for(var o=P(t.list),r=0;r<n.length;r++){var a=p.findIndexInList(n[r],o,t.dataKey);if(0===a)break;var i=o[a-1];o[a-1]=o[a],o[a]=i}t.onReorder&&t.onReorder({originalEvent:e,value:o,direction:"up"})}},pt:r("moveUpButton"),unstyled:i,"aria-label":n("moveUp"),__parentMetadata:{parent:t.metaData}}),e.createElement(v,{disabled:f,type:"button",icon:s,onClick:function(e){var n=t.selection;if(n&&n.length){for(var o=P(t.list),r=0;r<n.length;r++){var a=p.findIndexInList(n[r],o,t.dataKey);if(0===a)break;var i=o.splice(a,1)[0];o.unshift(i)}t.onReorder&&t.onReorder({originalEvent:e,value:o,direction:"top"})}},pt:r("moveTopButton"),unstyled:i,"aria-label":n("moveTop"),__parentMetadata:{parent:t.metaData}}),e.createElement(v,{disabled:f,type:"button",icon:m,onClick:function(e){var n=t.selection;if(n&&n.length){for(var o=P(t.list),r=n.length-1;r>=0;r--){var a=p.findIndexInList(n[r],o,t.dataKey);if(a===o.length-1)break;var i=o[a+1];o[a+1]=o[a],o[a]=i}t.onReorder&&t.onReorder({originalEvent:e,value:o,direction:"down"})}},pt:r("moveDownButton"),unstyled:i,"aria-label":n("moveDown"),__parentMetadata:{parent:t.metaData}}),e.createElement(v,{disabled:f,type:"button",icon:d,onClick:function(e){var n=t.selection;if(n&&n.length){for(var o=P(t.list),r=n.length-1;r>=0;r--){var a=p.findIndexInList(n[r],o,t.dataKey);if(a===o.length-1)break;var i=o.splice(a,1)[0];o.push(i)}t.onReorder&&t.onReorder({originalEvent:e,value:o,direction:"bottom"})}},pt:r("moveBottomButton"),unstyled:i,"aria-label":n("moveBottom"),__parentMetadata:{parent:t.metaData}}))});H.displayName="PickListControls";var U=e.memo(function(t){var n=l(),o=t.ptm,r=t.cx,a=t.template?t.template(t.value):t.value,i=n({className:u(t.className,r("item",{selected:t.selected,focused:t.focused})),id:t.id,onClick:function(e){t.onClick&&t.onClick({originalEvent:e,value:t.value,id:t.id})},onKeyDown:function(e){t.onKeyDown&&t.onKeyDown({originalEvent:e,value:t.value})},onFocus:function(e){t.onFocus&&t.onFocus(e)},onMouseDown:function(e){t.onMouseDown&&t.onMouseDown(e)},onMouseMove:t.onMouseMove,role:"option","aria-selected":t.selected,"data-p-highlight":t.selected,"data-p-focused":t.focused},o("item",{hostName:t.hostName,context:{selected:t.selected}}));return e.createElement("li",i,a,e.createElement(b,null))});function W(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function V(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?W(Object(n),!0).forEach(function(t){L(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):W(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}U.displayName="PickListItem";var J=e.memo(e.forwardRef(function(t,n){var o=l(),r=e.useRef(null),a=t.ptm,i=t.cx,c=function(e,n){return a(e,V({hostName:t.hostName},n))},s=function(e){return-1!==p.findIndexInList(e,t.selection,t.dataKey)},d=function(e){t.onFilter&&t.onFilter({originalEvent:e,value:e.target.value,type:t.type})},f=function(e){13===e.which&&e.preventDefault()};e.useImperativeHandle(n,function(){return{getElement:function(){return r.current}}});var v,g,h,y=function(e){var n;t.focusOnHover&&t.focusedList[t.type]&&(null==t||null===(n=t.changeFocusedOptionIndex)||void 0===n||n.call(t,e,t.type))},T=(v=o({className:i("header")},c("header")),t.header?e.createElement("div",v,p.getJSXElement(t.header,t)):null),b=function(){var n=o({className:i("filterIcon")},c("filterIcon")),r=m.getJSXIcon("source"===t.type?t.sourceFilterIcon||e.createElement(S,n):t.targetFilterIcon||e.createElement(S,n),V({},n),{props:t});if(t.showFilter){var a=o({className:i("filter")},c("filter")),l=o({type:"text",value:t.filterValue,onChange:d,onKeyDown:f,placeholder:t.placeholder,className:i("filterInput")},c("filterInput")),s=e.createElement("div",a,e.createElement("input",l),e.createElement("span",null," ",r," "));if(t.filterTemplate)s=p.getJSXElement(t.filterTemplate,{className:"p-picklist-filter",inputProps:{className:"p-picklist-filter-input p-inputtext p-component",onChange:d,onKeyDown:f},iconClassName:"p-picklist-filter-icon",element:s,props:t});var u=o({className:i("filterContainer")},c("filterContainer"));return e.createElement("div",u,s)}return null}(),I=(g=t.list?t.list.map(function(n,o){var r=t.parentId+"_"+t.type+"_"+o,l=s(n);return e.createElement(U,{hostName:t.hostName,key:r,id:r,index:o,focused:r===t.focusedOptionId,value:n,template:t.itemTemplate,selected:l,onClick:t.onItemClick,onKeyDown:t.onItemKeyDown,onMouseDown:function(e){return t.onOptionMouseDown(V(V({},e),{},{index:o,type:t.type}))},onMouseMove:function(){return y(o)},ptm:a,cx:i})}):null,h=o({ref:r,className:u(t.listClassName,i("list")),role:"listbox",id:t.parentId+"_"+t.type+"_list","aria-multiselectable":!0,"aria-activedescendant":t.ariaActivedescendant,tabIndex:t.list&&t.list.length>0?t.tabIndex:-1,onKeyDown:t.onListKeyDown,onFocus:function(e){t.onListFocus(e,t.type)},onBlur:t.onListBlur,style:t.style},c("list")),e.createElement("ul",h,g)),E=o({className:u(t.className,i("listWrapper"))},c("listWrapper"));return e.createElement("div",E,T,b,I)}));function Q(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,C(o.key),o)}}function Y(e,t,n){return t&&Q(e.prototype,t),n&&Q(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function q(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}J.displayName="PickListSubList";var G=Object.freeze({STARTS_WITH:"startsWith",CONTAINS:"contains",NOT_CONTAINS:"notContains",ENDS_WITH:"endsWith",EQUALS:"equals",NOT_EQUALS:"notEquals",IN:"in",NOT_IN:"notIn",LESS_THAN:"lt",LESS_THAN_OR_EQUAL_TO:"lte",GREATER_THAN:"gt",GREATER_THAN_OR_EQUAL_TO:"gte",BETWEEN:"between",DATE_IS:"dateIs",DATE_IS_NOT:"dateIsNot",DATE_BEFORE:"dateBefore",DATE_AFTER:"dateAfter",CUSTOM:"custom"}),X=Y(function e(){q(this,e)});L(X,"ripple",!1),L(X,"inputStyle","outlined"),L(X,"locale","en"),L(X,"appendTo",null),L(X,"cssTransition",!0),L(X,"autoZIndex",!0),L(X,"hideOverlaysOnDocumentScrolling",!1),L(X,"nonce",null),L(X,"nullSortOrder",1),L(X,"zIndex",{modal:1100,overlay:1e3,menu:1e3,tooltip:1100,toast:1200}),L(X,"pt",void 0),L(X,"filterMatchModeOptions",{text:[G.STARTS_WITH,G.CONTAINS,G.NOT_CONTAINS,G.ENDS_WITH,G.EQUALS,G.NOT_EQUALS],numeric:[G.EQUALS,G.NOT_EQUALS,G.LESS_THAN,G.LESS_THAN_OR_EQUAL_TO,G.GREATER_THAN,G.GREATER_THAN_OR_EQUAL_TO],date:[G.DATE_IS,G.DATE_IS_NOT,G.DATE_BEFORE,G.DATE_AFTER]}),L(X,"changeTheme",function(e,t,n,o){var r,a=document.getElementById(n);if(!a)throw Error("Element with id ".concat(n," not found."));var i=a.getAttribute("href").replace(e,t),l=document.createElement("link");l.setAttribute("rel","stylesheet"),l.setAttribute("id",n),l.setAttribute("href",i),l.addEventListener("load",function(){o&&o()}),null===(r=a.parentNode)||void 0===r||r.replaceChild(l,a)});var z={en:{accept:"Yes",addRule:"Add Rule",am:"AM",apply:"Apply",cancel:"Cancel",choose:"Choose",chooseDate:"Choose Date",chooseMonth:"Choose Month",chooseYear:"Choose Year",clear:"Clear",completed:"Completed",contains:"Contains",custom:"Custom",dateAfter:"Date is after",dateBefore:"Date is before",dateFormat:"mm/dd/yy",dateIs:"Date is",dateIsNot:"Date is not",dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],emptyFilterMessage:"No results found",emptyMessage:"No available options",emptySearchMessage:"No results found",emptySelectionMessage:"No selected item",endsWith:"Ends with",equals:"Equals",fileChosenMessage:"{0} files",fileSizeTypes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"],filter:"Filter",firstDayOfWeek:0,gt:"Greater than",gte:"Greater than or equal to",lt:"Less than",lte:"Less than or equal to",matchAll:"Match All",matchAny:"Match Any",medium:"Medium",monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],nextDecade:"Next Decade",nextHour:"Next Hour",nextMinute:"Next Minute",nextMonth:"Next Month",nextSecond:"Next Second",nextYear:"Next Year",noFileChosenMessage:"No file chosen",noFilter:"No Filter",notContains:"Not contains",notEquals:"Not equals",now:"Now",passwordPrompt:"Enter a password",pending:"Pending",pm:"PM",prevDecade:"Previous Decade",prevHour:"Previous Hour",prevMinute:"Previous Minute",prevMonth:"Previous Month",prevSecond:"Previous Second",prevYear:"Previous Year",reject:"No",removeRule:"Remove Rule",searchMessage:"{0} results are available",selectionMessage:"{0} items selected",showMonthAfterYear:!1,startsWith:"Starts with",strong:"Strong",today:"Today",upload:"Upload",weak:"Weak",weekHeader:"Wk",aria:{cancelEdit:"Cancel Edit",close:"Close",collapseLabel:"Collapse",collapseRow:"Row Collapsed",editRow:"Edit Row",expandLabel:"Expand",expandRow:"Row Expanded",falseLabel:"False",filterConstraint:"Filter Constraint",filterOperator:"Filter Operator",firstPageLabel:"First Page",gridView:"Grid View",hideFilterMenu:"Hide Filter Menu",jumpToPageDropdownLabel:"Jump to Page Dropdown",jumpToPageInputLabel:"Jump to Page Input",lastPageLabel:"Last Page",listLabel:"Option List",listView:"List View",moveAllToSource:"Move All to Source",moveAllToTarget:"Move All to Target",moveBottom:"Move Bottom",moveDown:"Move Down",moveToSource:"Move to Source",moveToTarget:"Move to Target",moveTop:"Move Top",moveUp:"Move Up",navigation:"Navigation",next:"Next",nextPageLabel:"Next Page",nullLabel:"Not Selected",otpLabel:"Please enter one time password character {0}",pageLabel:"Page {page}",passwordHide:"Hide Password",passwordShow:"Show Password",previous:"Previous",prevPageLabel:"Previous Page",removeLabel:"Remove",rotateLeft:"Rotate Left",rotateRight:"Rotate Right",rowsPerPageLabel:"Rows per page",saveEdit:"Save Edit",scrollTop:"Scroll Top",selectAll:"All items selected",selectLabel:"Select",selectRow:"Row Selected",showFilterMenu:"Show Filter Menu",slide:"Slide",slideNumber:"{slideNumber}",star:"1 star",stars:"{star} stars",trueLabel:"True",unselectAll:"All items unselected",unselectLabel:"Unselect",unselectRow:"Row Unselected",zoomImage:"Zoom Image",zoomIn:"Zoom In",zoomOut:"Zoom Out"}}};function Z(e,t){if(e.includes("__proto__")||e.includes("prototype"))throw new Error("Unsafe ariaKey detected");var n=X.locale;try{var o=$(n).aria[e];if(o)for(var r in t)t.hasOwnProperty(r)&&(o=o.replace("{".concat(r,"}"),t[r]));return o}catch(t){throw new Error("The ".concat(e," option is not found in the current locale('").concat(n,"')."))}}function $(e){var t=e||X.locale;if(t.includes("__proto__")||t.includes("prototype"))throw new Error("Unsafe locale detected");return z[t]}var ee=e.memo(function(t){var n=l(),o=c("(max-width: ".concat(t.breakpoint,")"),t.breakpoint),r=t.ptm,a=t.cx,i=t.unstyled;function s(n){switch(n){case"moveToTargetIcon":return t.moveToTargetIcon||o?t.moveToTargetIcon||e.createElement(y,null):t.moveToTargetIcon||e.createElement(N,null);case"moveAllToTargetIcon":return t.moveAllToTargetIcon||o?t.moveAllToTargetIcon||e.createElement(g,null):t.moveAllToTargetIcon||e.createElement(E,null);case"moveToSourceIcon":return t.moveToSourceIcon||o?t.moveToSourceIcon||e.createElement(T,null):t.moveToSourceIcon||e.createElement(w,null);case"moveAllToSourceIcon":return t.moveAllToSourceIcon||o?t.moveAllToSourceIcon||e.createElement(h,null):t.moveAllToSourceIcon||e.createElement(I,null);default:return null}}var d=m.getJSXIcon(s("moveToTargetIcon"),void 0,{props:t,viewChanged:o}),f=m.getJSXIcon(s("moveAllToTargetIcon"),void 0,{props:t,viewChanged:o}),S=m.getJSXIcon(s("moveToSourceIcon"),void 0,{props:t,viewChanged:o}),b=m.getJSXIcon(s("moveAllToSourceIcon"),void 0,{props:t,viewChanged:o}),A=p.isEmpty(t.sourceSelection)||p.isEmpty(t.visibleSourceList),k=p.isEmpty(t.targetSelection)||p.isEmpty(t.visibleTargetList),C=p.isEmpty(t.visibleSourceList),L=p.isEmpty(t.visibleTargetList),O=n({className:u(t.className,a("buttons"))},r("buttons",{hostName:t.hostName}));return e.createElement("div",O,e.createElement(v,{disabled:A,type:"button",icon:d,onClick:function(e){var n=t.sourceSelection;if(p.isNotEmpty(n)){for(var o=P(t.target),r=P(t.source),a=0;a<n.length;a++){var i=n[a];-1===p.findIndexInList(i,o,t.dataKey)&&o.push(r.splice(p.findIndexInList(i,r,t.dataKey),1)[0])}t.onTransfer&&t.onTransfer({originalEvent:e,source:r,target:o,direction:"toTarget"})}},pt:r("moveToTargetButton"),unstyled:i,"aria-label":Z("moveToTarget"),__parentMetadata:{parent:t.metaData}}),e.createElement(v,{disabled:C,type:"button",icon:f,onClick:function(e){if(t.source){var n=[].concat(P(t.target),P(t.visibleSourceList)),o=t.source.filter(function(e){return!t.visibleSourceList.some(function(t){return t===e})});t.onTransfer&&t.onTransfer({originalEvent:e,source:o,target:n,direction:"allToTarget"})}},pt:r("moveAllToTargetButton"),unstyled:i,"aria-label":Z("moveAllToTarget"),__parentMetadata:{parent:t.metaData}}),e.createElement(v,{disabled:k,type:"button",icon:S,onClick:function(e){var n=t.targetSelection;if(p.isNotEmpty(n)){for(var o=P(t.target),r=P(t.source),a=0;a<n.length;a++){var i=n[a];-1===p.findIndexInList(i,r,t.dataKey)&&r.push(o.splice(p.findIndexInList(i,o,t.dataKey),1)[0])}t.onTransfer&&t.onTransfer({originalEvent:e,source:r,target:o,direction:"toSource"})}},pt:r("moveToSourceButton"),unstyled:i,"aria-label":Z("moveToSource"),__parentMetadata:{parent:t.metaData}}),e.createElement(v,{disabled:L,type:"button",icon:b,onClick:function(e){if(t.source){var n=[].concat(P(t.source),P(t.visibleTargetList)),o=t.target.filter(function(e){return!t.visibleTargetList.some(function(t){return t===e})});t.onTransfer&&t.onTransfer({originalEvent:e,source:n,target:o,direction:"allToSource"})}},pt:r("moveAllToSourceButton"),unstyled:i,"aria-label":Z("moveAllToSource"),__parentMetadata:{parent:t.metaData}}))});function te(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function ne(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?te(Object(n),!0).forEach(function(t){L(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):te(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}ee.displayName="PickListTransferControls";var oe=e.memo(e.forwardRef(function(n,a){var c=l(),m=e.useContext(o),v=j.getProps(n,m),g=B(e.useState([]),2),h=g[0],y=g[1],T=B(e.useState([]),2),S=T[0],b=T[1],I=B(e.useState(""),2),E=I[0],w=I[1],N=B(e.useState(""),2),A=N[0],k=N[1],C=B(e.useState(v.id),2),O=C[0],M=C[1],x=B(e.useState(-1),2),D=x[0],F=x[1],_=B(e.useState(null),2),R=_[0],K=_[1],U=B(e.useState({source:!1,target:!1}),2),W=U[0],V=U[1],Q={props:v,state:{sourceSelection:h,targetSelection:S,sourceFilterValue:E,targetFilterValue:A,attributeSelector:O}},Y=j.setMetaData(Q),q=Y.ptm,G=Y.cx;i(j.css.styles,Y.isUnstyled,{name:"picklist"});var X=e.useRef(null),z=e.useRef(null),Z=e.useRef(null),$=e.useRef(null),te=e.useRef(null),oe=e.useRef(null),re=v.sourceSelection?v.sourceSelection:h,ae=v.targetSelection?v.targetSelection:S,ie=v.onSourceFilterChange?v.sourceFilterValue:E,le=v.onTargetFilterChange?v.targetFilterValue:A,ce=p.isNotEmpty(v.filterBy),se=ce&&v.showSourceFilter,ue=ce&&v.showTargetFilter,pe=function(e,t){if(e)switch(t){case"up":de(e,-1);break;case"top":e.scrollTop=0;break;case"down":de(e,1);break;case"bottom":setTimeout(function(){return e.scrollTop=e.scrollHeight},100)}},me=function(e,t,n){v.onChange&&v.onChange({originalEvent:e.originalEvent,source:t,target:n})},de=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=e.getElementsByClassName("p-highlight");p.isNotEmpty(n)&&f.scrollInView(e,-1===t?n[0]:n[n.length-1])},fe=function(e,t,n){"sourceSelection"===t?y(e.value):b(e.value),n&&n(e)},ve=function(e){var t=e.originalEvent,n=e.value,o=B("source"===e.type?[w,v.onSourceFilterChange]:[k,v.onTargetFilterChange],2),r=o[0],a=o[1];a?a({originalEvent:t,value:n}):r(n)},ge=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().toLocaleLowerCase(v.filterLocale);return ye(v.source,e)},he=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").trim().toLocaleLowerCase(v.filterLocale);return ye(v.target,e)},ye=function(e,t){var n=ce?v.filterBy.split(","):[];return r.filter(e,n,t,v.filterMatchMode,v.filterLocale)},Te=function(e,t){var n=B("source"===t?[ie,ge]:[le,he],2),o=n[0],r=n[1];return ce&&p.isNotEmpty(o)?r(o):e},Se=Te(v.source,"source"),be=Te(v.target,"target"),Ie=function(e){if(-1===D){var t=e&&e.children?P(e.children):[],n=Ee(e,t);return v.autoOptionFocus&&-1===n&&(n=we(e,t)),n}return-1},Ee=function(e,t){if(h.length||S.length){var n=f.findSingle(e,'[data-p-highlight="true"]');return p.findIndexInList(n,t)}return-1},we=function(e,t){var n=f.findSingle(e,'[data-pc-section="item"]');return p.findIndexInList(n,t)},Ne=function(e,t){V(ne(ne({},W),{},L({},t,!0)));var n=je(t),o=Ie(n);Ke(o,t),v.onFocus&&v.onFocus(e)},Ae=function(e,t){V(ne(ne({},W),{},L({},t,!1))),F(-1),v.onBlur&&v.onBlur(e)},ke=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=e.originalEvent,r=e.value,a=e.id,i="source"===t,l=P(i?re:ae),c=p.findIndexInList(r,l,v.dataKey),s=-1!==c,u=v.metaKeySelection;if(n||F(a),u){var m=o.metaKey||o.ctrlKey||o.shiftKey;s&&m?l.splice(c,1):(m||(l.length=0),l.push(r))}else s?l.splice(c,1):l.push(r);i?fe({originalEvent:o,value:l},"sourceSelection",v.onSourceSelectionChange):fe({originalEvent:o,value:l},"targetSelection",v.onTargetSelectionChange)},Ce=function(e){var t=e.index,n=e.type;V(ne(ne({},W),{},L({},n,!0))),F(t)},Le=function(e,t){switch(e.code){case"ArrowDown":Oe(e,t);break;case"ArrowUp":Me(e,t);break;case"Home":Fe(e,t);break;case"End":Pe(e,t);break;case"Enter":case"NumpadEnter":xe(e,t);break;case"Space":De(e,t);break;case"KeyA":if(e.ctrlKey){var n="source"===t;n?y(P(Se)):b(P(be)),fe({originalEvent:e,value:P(n?Se:be)},n?"sourceSelection":"targetSelection",n?v.onSourceSelectionChange:v.onTargetSelectionChange),e.preventDefault()}break;case"KeyD":if(e.ctrlKey){var o="source"===t;o?y([]):b([]),fe({originalEvent:e,value:[]},o?"sourceSelection":"targetSelection",o?v.onSourceSelectionChange:v.onTargetSelectionChange),e.preventDefault()}}},Oe=function(e,t){var n=_e(D,t),o=Te("source"===t?v.source:v.target,t);Ke(n,t),o&&o.length>0&&e.shiftKey&&ke({originalEvent:e,value:o[n]},t,!0),e.preventDefault()},Me=function(e,t){var n=Re(D,t),o=Te("source"===t?v.source:v.target,t);Ke(n,t),o&&o.length>0&&e.shiftKey&&ke({originalEvent:e,value:o[n]},t,!0),e.preventDefault()},xe=function(e,t){var n=je(t),o=Te("source"===t?v.source:v.target,t),r=f.find(n,'[data-pc-section="item"]'),a=f.findSingle(n,'[data-pc-section="item"][id='.concat(D,"]")),i=a&&a.getAttribute("id"),l=P(r).findIndex(function(e){return e===a});o&&o.length>0&&ke({originalEvent:e,value:o[l],id:i},t),e.preventDefault()},De=function(e,t){e.preventDefault();var n="source"===t,o=n?h:S;if(e.shiftKey&&o&&o.length>0){var r=n?Se:be,a=je(t),i=f.find(a,'[data-pc-section="item"]'),l=p.findIndexInList(o[0],P(r)),c=f.findSingle(a,'[data-pc-section="item"][id='.concat(D,"]")),s=P(i).findIndex(function(e){return e===c}),u=P(r).slice(Math.min(l,s),Math.max(l,s)+1);n?fe({originalEvent:e,value:u},"sourceSelection",v.onSourceSelectionChange):fe({originalEvent:e,value:u},"targetSelection",v.onTargetSelectionChange)}else xe(e,t)},Fe=function(e,t){if(e.ctrlKey&&e.shiftKey){var n="source"===t,o=n?Se:be,r=je(t),a=f.find(r,'[data-pc-section="item"]'),i=f.findSingle(r,'[data-pc-section="item"][id='.concat(D,"]")),l=P(a).findIndex(function(e){return e===i}),c=P(o).slice(0,l+1);n?fe({originalEvent:e,value:c},"sourceSelection",v.onSourceSelectionChange):fe({originalEvent:e,value:c},"targetSelection",v.onTargetSelectionChange)}else Ke(0,t);e.preventDefault()},Pe=function(e,t){var n=je(t),o=f.find(n,'[data-pc-section="item"]');if(e.ctrlKey&&e.shiftKey){var r="source"===t,a=r?Se:be,i=f.findSingle(n,'[data-pc-section="item"][id='.concat(D,"]")),l=P(o).findIndex(function(e){return e===i}),c=P(a).slice(l,o.length);r?fe({originalEvent:e,value:c},"sourceSelection",v.onSourceSelectionChange):fe({originalEvent:e,value:c},"targetSelection",v.onTargetSelectionChange)}else Ke(o.length-1,t);e.preventDefault()},_e=function(e,t){var n=je(t),o=P(f.find(n,'[data-pc-section="item"]')).findIndex(function(t){return t.id===e});return o>-1?o+1:0},Re=function(e,t){var n=je(t),o=P(f.find(n,'[data-pc-section="item"]')).findIndex(function(t){return t.id===e});return o>-1?o-1:0},Ke=function(e,t){var n,o=je(t),r=f.find(o,'[data-pc-section="item"]');if(e>=r.length)n=r.length-1;else{if(e<0)return;n=e}F(r[n].getAttribute("id")),Be(r[n].getAttribute("id"),t)},Be=function(e,t){var n=je(t),o=f.findSingle(n,'[data-pc-section="item"][id="'.concat(e,'"]'));o&&o.scrollIntoView&&o.scrollIntoView({block:"nearest",inline:"start"})},je=function(e){return"source"===e?z.current.getElement():Z.current.getElement()},He=function(){if(!oe.current){oe.current=f.createInlineStyle(m&&m.nonce||t.nonce,m&&m.styleContainer);var e="\n@media screen and (max-width: ".concat(v.breakpoint,") {\n .p-picklist[").concat(O,"] {\n flex-direction: column;\n }\n\n .p-picklist[").concat(O,"] .p-picklist-buttons {\n padding: var(--content-padding);\n flex-direction: row;\n }\n\n .p-picklist[").concat(O,"] .p-picklist-buttons .p-button {\n margin-right: var(--inline-spacing);\n margin-bottom: 0;\n }\n\n .p-picklist[").concat(O,"] .p-picklist-buttons .p-button:last-child {\n margin-right: 0;\n }\n}\n");oe.current.innerHTML=e}};e.useImperativeHandle(a,function(){return{props:v,getElement:function(){return X.current}}}),s(function(){return O&&(X.current.setAttribute(O,""),He()),function(){oe.current=f.removeInlineStyle(oe.current)}},[O,v.breakpoint]),s(function(){v.id||O||M(d()),$.current&&(pe($.current,te.current),$.current=null,te.current=null)}),s(function(){K(-1!==D?D:null)},[D]);var Ue=v.sourceItemTemplate?v.sourceItemTemplate:v.itemTemplate,We=v.targetItemTemplate?v.targetItemTemplate:v.itemTemplate,Ve=c({id:O,ref:X,className:u(v.className,G("root")),style:v.style},j.getOtherProps(v),q("root"));return e.createElement("div",Ve,v.showSourceControls&&e.createElement(H,{hostName:"PickList",list:v.source,selection:re,onReorder:function(e){me(e,e.value,v.target),$.current=je("source"),te.current=e.direction},className:G("sourceControls"),dataKey:v.dataKey,moveUpIcon:v.moveUpIcon,moveTopIcon:v.moveTopIcon,moveDownIcon:v.moveDownIcon,moveBottomIcon:v.moveBottomIcon,ptm:q,cx:G,unstyled:v.unstyled,metaData:Q}),e.createElement(J,{hostName:"PickList",ref:z,type:"source",list:Se,parentId:O,selection:re,onSelectionChange:function(e){return fe(e,"sourceSelection",v.onSourceSelectionChange)},onListKeyDown:function(e){return Le(e,"source")},onListFocus:function(e){return Ne(e,"source")},onListBlur:function(e){return Ae(e,"source")},onOptionMouseDown:function(e){return Ce(e)},onItemClick:function(e){return ke(e,"source")},focusedOptionId:W.source?R:null,ariaActivedescendant:W.source?R:null,itemTemplate:Ue,header:v.sourceHeader,style:v.sourceStyle,className:G("listSourceWrapper"),listClassName:G("listSource"),metaKeySelection:v.metaKeySelection,tabIndex:v.tabIndex,dataKey:v.dataKey,filterValue:ie,onFilter:ve,showFilter:se,placeholder:v.sourceFilterPlaceholder,filterTemplate:v.sourceFilterTemplate,sourceFilterIcon:v.sourceFilterIcon,ptm:q,cx:G,focusedList:W,changeFocusedOptionIndex:Ke,focusOnHover:v.focusOnHover}),e.createElement(ee,{hostName:"PickList",onTransfer:function(e){var t=e.originalEvent,n=e.source,o=e.target,r=[];switch(e.direction){case"toTarget":r=re,v.onMoveToTarget&&v.onMoveToTarget({originalEvent:t,value:r});break;case"allToTarget":r=v.source,v.onMoveAllToTarget&&v.onMoveAllToTarget({originalEvent:t,value:r}),r=[];break;case"toSource":r=ae,v.onMoveToSource&&v.onMoveToSource({originalEvent:t,value:r});break;case"allToSource":r=v.target,v.onMoveAllToSource&&v.onMoveAllToSource({originalEvent:t,value:r}),r=[]}fe({originalEvent:t,value:r},"sourceSelection",v.onSourceSelectionChange),fe({originalEvent:t,value:r},"targetSelection",v.onTargetSelectionChange),b([]),y([]),me(e,n,o)},source:v.source,visibleSourceList:Se,target:v.target,breakpoint:v.breakpoint,visibleTargetList:be,sourceSelection:re,targetSelection:ae,dataKey:v.dataKey,moveToTargetIcon:v.moveToTargetIcon,moveAllToTargetIcon:v.moveAllToTargetIcon,moveToSourceIcon:v.moveToSourceIcon,moveAllToSourceIcon:v.moveAllToSourceIcon,ptm:q,cx:G,unstyled:v.unstyled,metaData:Q}),e.createElement(J,{hostName:"PickList",ref:Z,type:"target",list:be,selection:ae,parentId:O,onSelectionChange:function(e){return fe(e,"targetSelection",v.onTargetSelectionChange)},onListKeyDown:function(e){return Le(e,"target")},onListFocus:function(e){return Ne(e,"target")},onListBlur:function(e){return Ae(e,"target")},onOptionMouseDown:function(e){return Ce(e)},onItemClick:function(e){return ke(e,"target")},focusedOptionId:W.target?R:null,ariaActivedescendant:W.target?R:null,itemTemplate:We,header:v.targetHeader,style:v.targetStyle,className:G("listTargetWrapper"),listClassName:G("listWrapper"),metaKeySelection:v.metaKeySelection,tabIndex:v.tabIndex,dataKey:v.dataKey,filterValue:le,onFilter:ve,showFilter:ue,placeholder:v.targetFilterPlaceholder,filterTemplate:v.targetFilterTemplate,targetFilterIcon:v.targetFilterIcon,ptm:q,cx:G,focusedList:W,changeFocusedOptionIndex:Ke,focusOnHover:v.focusOnHover}),v.showTargetControls&&e.createElement(H,{hostName:"PickList",list:v.target,selection:ae,onReorder:function(e){me(e,v.source,e.value),$.current=je("target"),te.current=e.direction},className:G("targetControls"),dataKey:v.dataKey,moveUpIcon:v.moveUpIcon,moveTopIcon:v.moveTopIcon,moveDownIcon:v.moveDownIcon,moveBottomIcon:v.moveBottomIcon,ptm:q,cx:G,unstyled:v.unstyled,metaData:Q}))}));oe.displayName="PickList";export{oe as PickList};