tweakpane-plugin-search-list
Version:
searchable select list plugin for Tweakpane
2 lines (1 loc) • 25.9 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).TweakpaneSearchListPlugin=e()}(this,(function(){"use strict";class t{constructor(){this.observers_={}}on(t,e){let n=this.observers_[t];return n||(n=this.observers_[t]=[]),n.push({handler:e}),this}off(t,e){const n=this.observers_[t];return n&&(this.observers_[t]=n.filter((t=>t.handler!==e))),this}emit(t,e){const n=this.observers_[t];n&&n.forEach((t=>{t.handler(e)}))}}const e="tp";function n(t){return(n,i)=>[e,"-",t,"v",n?`_${n}`:"",i?`-${i}`:""].join("")}class i{constructor(e,n){var i;this.constraint_=null==n?void 0:n.constraint,this.equals_=null!==(i=null==n?void 0:n.equals)&&void 0!==i?i:(t,e)=>t===e,this.emitter=new t,this.rawValue_=e}get constraint(){return this.constraint_}get rawValue(){return this.rawValue_}set rawValue(t){this.setRawValue(t,{forceEmit:!1,last:!0})}setRawValue(t,e){const n=null!=e?e:{forceEmit:!1,last:!0},i=this.constraint_?this.constraint_.constrain(t):t;(!this.equals_(this.rawValue_,i)||n.forceEmit)&&(this.emitter.emit("beforechange",{sender:this}),this.rawValue_=i,this.emitter.emit("change",{options:n,rawValue:i,sender:this}))}}class o{constructor(e){this.emitter=new t,this.value_=e}get rawValue(){return this.value_}set rawValue(t){this.setRawValue(t,{forceEmit:!1,last:!0})}setRawValue(t,e){const n=null!=e?e:{forceEmit:!1,last:!0};(this.value_!==t||n.forceEmit)&&(this.emitter.emit("beforechange",{sender:this}),this.value_=t,this.emitter.emit("change",{options:n,rawValue:this.value_,sender:this}))}}function r(t,e){const n=null==e?void 0:e.constraint,r=null==e?void 0:e.equals;return n||r?new i(t,e):new o(t)}class a{constructor(e){this.emitter=new t,this.valMap_=e;for(const t in this.valMap_){this.valMap_[t].emitter.on("change",(()=>{this.emitter.emit("change",{key:t,sender:this})}))}}static createCore(t){return Object.keys(t).reduce(((e,n)=>Object.assign(e,{[n]:r(t[n])})),{})}static fromObject(t){const e=this.createCore(t);return new a(e)}get(t){return this.valMap_[t].rawValue}set(t,e){this.valMap_[t].rawValue=e}value(t){return this.valMap_[t]}}class s{constructor(t){this.constraints=t}constrain(t){return this.constraints.reduce(((t,e)=>e.constrain(t)),t)}}class c{constructor(t){this.options=t}constrain(t){const e=this.options;if(0===e.length)return t;return e.filter((e=>e.value===t)).length>0?t:e[0].value}}const l=n("txt");class u{constructor(t,e){this.onChange_=this.onChange_.bind(this),this.element=t.createElement("div"),this.element.classList.add(l()),e.viewProps.bindClassModifiers(this.element),this.props_=e.props,this.props_.emitter.on("change",this.onChange_);const n=t.createElement("input");n.classList.add(l("i")),n.type="text",e.viewProps.bindDisabled(n),this.element.appendChild(n),this.inputElement=n,e.value.emitter.on("change",this.onChange_),this.value_=e.value,this.refresh()}refresh(){const t=this.props_.get("formatter");this.inputElement.value=t(this.value_.rawValue)}onChange_(){this.refresh()}}function p(t){return null!=t?new c(function(t){if(Array.isArray(t))return t;const e=[];return Object.keys(t).forEach((n=>{e.push({text:n,value:t[n]})})),e}(t)):null}var f="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var d=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},h="object"==typeof f&&f&&f.Object===Object&&f,v="object"==typeof self&&self&&self.Object===Object&&self,m=h||v||Function("return this")(),g=m,b=function(){return g.Date.now()},w=/\s/;var y=function(t){for(var e=t.length;e--&&w.test(t.charAt(e)););return e},x=y,O=/^\s+/;var _=function(t){return t?t.slice(0,x(t)+1).replace(O,""):t},E=m.Symbol,j=E,k=Object.prototype,T=k.hasOwnProperty,V=k.toString,L=j?j.toStringTag:void 0;var C=function(t){var e=T.call(t,L),n=t[L];try{t[L]=void 0;var i=!0}catch(t){}var o=V.call(t);return i&&(e?t[L]=n:delete t[L]),o},P=Object.prototype.toString;var M=C,D=function(t){return P.call(t)},S=E?E.toStringTag:void 0;var A=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":S&&S in Object(t)?M(t):D(t)},B=function(t){return null!=t&&"object"==typeof t};var W=_,H=d,R=function(t){return"symbol"==typeof t||B(t)&&"[object Symbol]"==A(t)},N=/^[-+]0x[0-9a-f]+$/i,I=/^0b[01]+$/i,U=/^0o[0-7]+$/i,q=parseInt;var z=d,F=b,$=function(t){if("number"==typeof t)return t;if(R(t))return NaN;if(H(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=H(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=W(t);var n=I.test(t);return n||U.test(t)?q(t.slice(2),n?2:8):N.test(t)?NaN:+t},X=Math.max,Y=Math.min;var G=function(t,e,n){var i,o,r,a,s,c,l=0,u=!1,p=!1,f=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function d(e){var n=i,r=o;return i=o=void 0,l=e,a=t.apply(r,n)}function h(t){return l=t,s=setTimeout(m,e),u?d(t):a}function v(t){var n=t-c;return void 0===c||n>=e||n<0||p&&t-l>=r}function m(){var t=F();if(v(t))return g(t);s=setTimeout(m,function(t){var n=e-(t-c);return p?Y(n,r-(t-l)):n}(t))}function g(t){return s=void 0,f&&i?d(t):(i=o=void 0,a)}function b(){var t=F(),n=v(t);if(i=arguments,o=this,c=t,n){if(void 0===s)return h(c);if(p)return clearTimeout(s),s=setTimeout(m,e),d(c)}return void 0===s&&(s=setTimeout(m,e)),a}return e=$(e)||0,z(n)&&(u=!!n.leading,r=(p="maxWait"in n)?X($(n.maxWait)||0,e):r,f="trailing"in n?!!n.trailing:f),b.cancel=function(){void 0!==s&&clearTimeout(s),l=0,i=c=o=s=void 0},b.flush=function(){return void 0===s?a:g(F())},b},J={left:"right",right:"left",bottom:"top",top:"bottom"};function K(t){return t.replace(/left|right|bottom|top/g,(function(t){return J[t]}))}var Q="top",Z="bottom",tt="right",et="left",nt="auto",it=[Q,Z,tt,et],ot="start",rt="end",at="viewport",st="popper",ct=it.reduce((function(t,e){return t.concat([e+"-"+ot,e+"-"+rt])}),[]),lt=[].concat(it,[nt]).reduce((function(t,e){return t.concat([e,e+"-"+ot,e+"-"+rt])}),[]),ut=["beforeRead","read","afterRead","beforeMain","main","afterMain","beforeWrite","write","afterWrite"];function pt(t){return t.split("-")[0]}var ft={start:"end",end:"start"};function dt(t){return t.replace(/start|end/g,(function(t){return ft[t]}))}function ht(t){if(null==t)return window;if("[object Window]"!==t.toString()){var e=t.ownerDocument;return e&&e.defaultView||window}return t}function vt(t){return t instanceof ht(t).Element||t instanceof Element}function mt(t){return t instanceof ht(t).HTMLElement||t instanceof HTMLElement}function gt(t){return"undefined"!=typeof ShadowRoot&&(t instanceof ht(t).ShadowRoot||t instanceof ShadowRoot)}function bt(t){return((vt(t)?t.ownerDocument:t.document)||window.document).documentElement}var wt=Math.round;function yt(t,e){void 0===e&&(e=!1);var n=t.getBoundingClientRect(),i=1,o=1;if(mt(t)&&e){var r=t.offsetHeight,a=t.offsetWidth;a>0&&(i=n.width/a||1),r>0&&(o=n.height/r||1)}return{width:wt(n.width/i),height:wt(n.height/o),top:wt(n.top/o),right:wt(n.right/i),bottom:wt(n.bottom/o),left:wt(n.left/i),x:wt(n.left/i),y:wt(n.top/o)}}function xt(t){var e=ht(t);return{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Ot(t){return yt(bt(t)).left+xt(t).scrollLeft}function _t(t){return ht(t).getComputedStyle(t)}var Et=Math.max,jt=Math.min,kt=Math.round;function Tt(t){return t?(t.nodeName||"").toLowerCase():null}function Vt(t){return"html"===Tt(t)?t:t.assignedSlot||t.parentNode||(gt(t)?t.host:null)||bt(t)}function Lt(t){var e=_t(t),n=e.overflow,i=e.overflowX,o=e.overflowY;return/auto|scroll|overlay|hidden/.test(n+o+i)}function Ct(t){return["html","body","#document"].indexOf(Tt(t))>=0?t.ownerDocument.body:mt(t)&&Lt(t)?t:Ct(Vt(t))}function Pt(t,e){var n;void 0===e&&(e=[]);var i=Ct(t),o=i===(null==(n=t.ownerDocument)?void 0:n.body),r=ht(i),a=o?[r].concat(r.visualViewport||[],Lt(i)?i:[]):i,s=e.concat(a);return o?s:s.concat(Pt(Vt(a)))}function Mt(t){return["table","td","th"].indexOf(Tt(t))>=0}function Dt(t){return mt(t)&&"fixed"!==_t(t).position?t.offsetParent:null}function St(t){for(var e=ht(t),n=Dt(t);n&&Mt(n)&&"static"===_t(n).position;)n=Dt(n);return n&&("html"===Tt(n)||"body"===Tt(n)&&"static"===_t(n).position)?e:n||function(t){var e=-1!==navigator.userAgent.toLowerCase().indexOf("firefox");if(-1!==navigator.userAgent.indexOf("Trident")&&mt(t)&&"fixed"===_t(t).position)return null;for(var n=Vt(t);mt(n)&&["html","body"].indexOf(Tt(n))<0;){var i=_t(n);if("none"!==i.transform||"none"!==i.perspective||"paint"===i.contain||-1!==["transform","perspective"].indexOf(i.willChange)||e&&"filter"===i.willChange||e&&i.filter&&"none"!==i.filter)return n;n=n.parentNode}return null}(t)||e}function At(t){return Object.assign({},t,{left:t.x,top:t.y,right:t.x+t.width,bottom:t.y+t.height})}function Bt(t,e){return e===at?At(function(t){var e=ht(t),n=bt(t),i=e.visualViewport,o=n.clientWidth,r=n.clientHeight,a=0,s=0;return i&&(o=i.width,r=i.height,/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(a=i.offsetLeft,s=i.offsetTop)),{width:o,height:r,x:a+Ot(t),y:s}}(t)):mt(e)?function(t){var e=yt(t);return e.top=e.top+t.clientTop,e.left=e.left+t.clientLeft,e.bottom=e.top+t.clientHeight,e.right=e.left+t.clientWidth,e.width=t.clientWidth,e.height=t.clientHeight,e.x=e.left,e.y=e.top,e}(e):At(function(t){var e,n=bt(t),i=xt(t),o=null==(e=t.ownerDocument)?void 0:e.body,r=Et(n.scrollWidth,n.clientWidth,o?o.scrollWidth:0,o?o.clientWidth:0),a=Et(n.scrollHeight,n.clientHeight,o?o.scrollHeight:0,o?o.clientHeight:0),s=-i.scrollLeft+Ot(t),c=-i.scrollTop;return"rtl"===_t(o||n).direction&&(s+=Et(n.clientWidth,o?o.clientWidth:0)-r),{width:r,height:a,x:s,y:c}}(bt(t)))}function Wt(t){var e=Pt(Vt(t)),n=["absolute","fixed"].indexOf(_t(t).position)>=0&&mt(t)?St(t):t;return vt(n)?e.filter((function(t){return vt(t)&&function(t,e){var n=e.getRootNode&&e.getRootNode();if(t.contains(e))return!0;if(n&>(n)){var i=e;do{if(i&&t.isSameNode(i))return!0;i=i.parentNode||i.host}while(i)}return!1}(t,n)&&"body"!==Tt(t)})):[]}function Ht(t){return t.split("-")[1]}function Rt(t){var e,n=t.reference,i=t.element,o=t.placement,r=o?pt(o):null,a=o?Ht(o):null,s=n.x+n.width/2-i.width/2,c=n.y+n.height/2-i.height/2;switch(r){case Q:e={x:s,y:n.y-i.height};break;case Z:e={x:s,y:n.y+n.height};break;case tt:e={x:n.x+n.width,y:c};break;case et:e={x:n.x-i.width,y:c};break;default:e={x:n.x,y:n.y}}var l=r?function(t){return["top","bottom"].indexOf(t)>=0?"x":"y"}(r):null;if(null!=l){var u="y"===l?"height":"width";switch(a){case ot:e[l]=e[l]-(n[u]/2-i[u]/2);break;case rt:e[l]=e[l]+(n[u]/2-i[u]/2)}}return e}function Nt(t,e){void 0===e&&(e={});var n,i=e,o=i.placement,r=void 0===o?t.placement:o,a=i.boundary,s=void 0===a?"clippingParents":a,c=i.rootBoundary,l=void 0===c?at:c,u=i.elementContext,p=void 0===u?st:u,f=i.altBoundary,d=void 0!==f&&f,h=i.padding,v=void 0===h?0:h,m=function(t){return Object.assign({},{top:0,right:0,bottom:0,left:0},t)}("number"!=typeof v?v:(n=v,it.reduce((function(t,e){return t[e]=n,t}),{}))),g=p===st?"reference":st,b=t.rects.popper,w=t.elements[d?g:p],y=function(t,e,n){var i="clippingParents"===e?Wt(t):[].concat(e),o=[].concat(i,[n]),r=o[0],a=o.reduce((function(e,n){var i=Bt(t,n);return e.top=Et(i.top,e.top),e.right=jt(i.right,e.right),e.bottom=jt(i.bottom,e.bottom),e.left=Et(i.left,e.left),e}),Bt(t,r));return a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}(vt(w)?w:w.contextElement||bt(t.elements.popper),s,l),x=yt(t.elements.reference),O=Rt({reference:x,element:b,strategy:"absolute",placement:r}),_=At(Object.assign({},b,O)),E=p===st?_:x,j={top:y.top-E.top+m.top,bottom:E.bottom-y.bottom+m.bottom,left:y.left-E.left+m.left,right:E.right-y.right+m.right},k=t.modifiersData.offset;if(p===st&&k){var T=k[r];Object.keys(j).forEach((function(t){var e=[tt,Z].indexOf(t)>=0?1:-1,n=[Q,Z].indexOf(t)>=0?"y":"x";j[t]+=T[n]*e}))}return j}function It(t,e){void 0===e&&(e={});var n=e,i=n.placement,o=n.boundary,r=n.rootBoundary,a=n.padding,s=n.flipVariations,c=n.allowedAutoPlacements,l=void 0===c?lt:c,u=Ht(i),p=u?s?ct:ct.filter((function(t){return Ht(t)===u})):it,f=p.filter((function(t){return l.indexOf(t)>=0}));0===f.length&&(f=p);var d=f.reduce((function(e,n){return e[n]=Nt(t,{placement:n,boundary:o,rootBoundary:r,padding:a})[pt(n)],e}),{});return Object.keys(d).sort((function(t,e){return d[t]-d[e]}))}var Ut={name:"flip",enabled:!0,phase:"main",fn:function(t){var e=t.state,n=t.options,i=t.name;if(!e.modifiersData[i]._skip){for(var o=n.mainAxis,r=void 0===o||o,a=n.altAxis,s=void 0===a||a,c=n.fallbackPlacements,l=n.padding,u=n.boundary,p=n.rootBoundary,f=n.altBoundary,d=n.flipVariations,h=void 0===d||d,v=n.allowedAutoPlacements,m=e.options.placement,g=pt(m),b=c||(g===m||!h?[K(m)]:function(t){if(pt(t)===nt)return[];var e=K(t);return[dt(t),e,dt(e)]}(m)),w=[m].concat(b).reduce((function(t,n){return t.concat(pt(n)===nt?It(e,{placement:n,boundary:u,rootBoundary:p,padding:l,flipVariations:h,allowedAutoPlacements:v}):n)}),[]),y=e.rects.reference,x=e.rects.popper,O=new Map,_=!0,E=w[0],j=0;j<w.length;j++){var k=w[j],T=pt(k),V=Ht(k)===ot,L=[Q,Z].indexOf(T)>=0,C=L?"width":"height",P=Nt(e,{placement:k,boundary:u,rootBoundary:p,altBoundary:f,padding:l}),M=L?V?tt:et:V?Z:Q;y[C]>x[C]&&(M=K(M));var D=K(M),S=[];if(r&&S.push(P[T]<=0),s&&S.push(P[M]<=0,P[D]<=0),S.every((function(t){return t}))){E=k,_=!1;break}O.set(k,S)}if(_)for(var A=function(t){var e=w.find((function(e){var n=O.get(e);if(n)return n.slice(0,t).every((function(t){return t}))}));if(e)return E=e,"break"},B=h?3:1;B>0;B--){if("break"===A(B))break}e.placement!==E&&(e.modifiersData[i]._skip=!0,e.placement=E,e.reset=!0)}},requiresIfExists:["offset"],data:{_skip:!1}};function qt(t,e,n){void 0===n&&(n=!1);var i,o,r=mt(e),a=mt(e)&&function(t){var e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,i=e.height/t.offsetHeight||1;return 1!==n||1!==i}(e),s=bt(e),c=yt(t,a),l={scrollLeft:0,scrollTop:0},u={x:0,y:0};return(r||!r&&!n)&&(("body"!==Tt(e)||Lt(s))&&(l=(i=e)!==ht(i)&&mt(i)?{scrollLeft:(o=i).scrollLeft,scrollTop:o.scrollTop}:xt(i)),mt(e)?((u=yt(e,!0)).x+=e.clientLeft,u.y+=e.clientTop):s&&(u.x=Ot(s))),{x:c.left+l.scrollLeft-u.x,y:c.top+l.scrollTop-u.y,width:c.width,height:c.height}}function zt(t){var e=new Map,n=new Set,i=[];function o(t){n.add(t.name),[].concat(t.requires||[],t.requiresIfExists||[]).forEach((function(t){if(!n.has(t)){var i=e.get(t);i&&o(i)}})),i.push(t)}return t.forEach((function(t){e.set(t.name,t)})),t.forEach((function(t){n.has(t.name)||o(t)})),i}var Ft={placement:"bottom",modifiers:[],strategy:"absolute"};function $t(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return!e.some((function(t){return!(t&&"function"==typeof t.getBoundingClientRect)}))}function Xt(t){void 0===t&&(t={});var e=t,n=e.defaultModifiers,i=void 0===n?[]:n,o=e.defaultOptions,r=void 0===o?Ft:o;return function(t,e,n){void 0===n&&(n=r);var o,a,s={placement:"bottom",orderedModifiers:[],options:Object.assign({},Ft,r),modifiersData:{},elements:{reference:t,popper:e},attributes:{},styles:{}},c=[],l=!1,u={state:s,setOptions:function(n){var o="function"==typeof n?n(s.options):n;p(),s.options=Object.assign({},r,s.options,o),s.scrollParents={reference:vt(t)?Pt(t):t.contextElement?Pt(t.contextElement):[],popper:Pt(e)};var a,l,f=function(t){var e=zt(t);return ut.reduce((function(t,n){return t.concat(e.filter((function(t){return t.phase===n})))}),[])}((a=[].concat(i,s.options.modifiers),l=a.reduce((function(t,e){var n=t[e.name];return t[e.name]=n?Object.assign({},n,e,{options:Object.assign({},n.options,e.options),data:Object.assign({},n.data,e.data)}):e,t}),{}),Object.keys(l).map((function(t){return l[t]}))));return s.orderedModifiers=f.filter((function(t){return t.enabled})),s.orderedModifiers.forEach((function(t){var e=t.name,n=t.options,i=void 0===n?{}:n,o=t.effect;if("function"==typeof o){var r=o({state:s,name:e,instance:u,options:i}),a=function(){};c.push(r||a)}})),u.update()},forceUpdate:function(){if(!l){var t=s.elements,e=t.reference,n=t.popper;if($t(e,n)){var i,o,r,a;s.rects={reference:qt(e,St(n),"fixed"===s.options.strategy),popper:(i=n,o=yt(i),r=i.offsetWidth,a=i.offsetHeight,Math.abs(o.width-r)<=1&&(r=o.width),Math.abs(o.height-a)<=1&&(a=o.height),{x:i.offsetLeft,y:i.offsetTop,width:r,height:a})},s.reset=!1,s.placement=s.options.placement,s.orderedModifiers.forEach((function(t){return s.modifiersData[t.name]=Object.assign({},t.data)}));for(var c=0;c<s.orderedModifiers.length;c++)if(!0!==s.reset){var p=s.orderedModifiers[c],f=p.fn,d=p.options,h=void 0===d?{}:d,v=p.name;"function"==typeof f&&(s=f({state:s,options:h,name:v,instance:u})||s)}else s.reset=!1,c=-1}}},update:(o=function(){return new Promise((function(t){u.forceUpdate(),t(s)}))},function(){return a||(a=new Promise((function(t){Promise.resolve().then((function(){a=void 0,t(o())}))}))),a}),destroy:function(){p(),l=!0}};if(!$t(t,e))return u;function p(){c.forEach((function(t){return t()})),c=[]}return u.setOptions(n).then((function(t){!l&&n.onFirstUpdate&&n.onFirstUpdate(t)})),u}}Xt();var Yt={passive:!0};var Gt={top:"auto",right:"auto",bottom:"auto",left:"auto"};function Jt(t){var e,n=t.popper,i=t.popperRect,o=t.placement,r=t.variation,a=t.offsets,s=t.position,c=t.gpuAcceleration,l=t.adaptive,u=t.roundOffsets,p=!0===u?function(t){var e=t.x,n=t.y,i=window.devicePixelRatio||1;return{x:kt(kt(e*i)/i)||0,y:kt(kt(n*i)/i)||0}}(a):"function"==typeof u?u(a):a,f=p.x,d=void 0===f?0:f,h=p.y,v=void 0===h?0:h,m=a.hasOwnProperty("x"),g=a.hasOwnProperty("y"),b=et,w=Q,y=window;if(l){var x=St(n),O="clientHeight",_="clientWidth";x===ht(n)&&"static"!==_t(x=bt(n)).position&&"absolute"===s&&(O="scrollHeight",_="scrollWidth"),x=x,o!==Q&&(o!==et&&o!==tt||r!==rt)||(w=Z,v-=x[O]-i.height,v*=c?1:-1),o!==et&&(o!==Q&&o!==Z||r!==rt)||(b=tt,d-=x[_]-i.width,d*=c?1:-1)}var E,j=Object.assign({position:s},l&&Gt);return c?Object.assign({},j,((E={})[w]=g?"0":"",E[b]=m?"0":"",E.transform=(y.devicePixelRatio||1)<=1?"translate("+d+"px, "+v+"px)":"translate3d("+d+"px, "+v+"px, 0)",E)):Object.assign({},j,((e={})[w]=g?v+"px":"",e[b]=m?d+"px":"",e.transform="",e))}var Kt=Xt({defaultModifiers:[{name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:function(t){var e=t.state,n=t.instance,i=t.options,o=i.scroll,r=void 0===o||o,a=i.resize,s=void 0===a||a,c=ht(e.elements.popper),l=[].concat(e.scrollParents.reference,e.scrollParents.popper);return r&&l.forEach((function(t){t.addEventListener("scroll",n.update,Yt)})),s&&c.addEventListener("resize",n.update,Yt),function(){r&&l.forEach((function(t){t.removeEventListener("scroll",n.update,Yt)})),s&&c.removeEventListener("resize",n.update,Yt)}},data:{}},{name:"popperOffsets",enabled:!0,phase:"read",fn:function(t){var e=t.state,n=t.name;e.modifiersData[n]=Rt({reference:e.rects.reference,element:e.rects.popper,strategy:"absolute",placement:e.placement})},data:{}},{name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:function(t){var e=t.state,n=t.options,i=n.gpuAcceleration,o=void 0===i||i,r=n.adaptive,a=void 0===r||r,s=n.roundOffsets,c=void 0===s||s,l={placement:pt(e.placement),variation:Ht(e.placement),popper:e.elements.popper,popperRect:e.rects.popper,gpuAcceleration:o};null!=e.modifiersData.popperOffsets&&(e.styles.popper=Object.assign({},e.styles.popper,Jt(Object.assign({},l,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:a,roundOffsets:c})))),null!=e.modifiersData.arrow&&(e.styles.arrow=Object.assign({},e.styles.arrow,Jt(Object.assign({},l,{offsets:e.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:c})))),e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-placement":e.placement})},data:{}},{name:"applyStyles",enabled:!0,phase:"write",fn:function(t){var e=t.state;Object.keys(e.elements).forEach((function(t){var n=e.styles[t]||{},i=e.attributes[t]||{},o=e.elements[t];mt(o)&&Tt(o)&&(Object.assign(o.style,n),Object.keys(i).forEach((function(t){var e=i[t];!1===e?o.removeAttribute(t):o.setAttribute(t,!0===e?"":e)})))}))},effect:function(t){var e=t.state,n={popper:{position:e.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(e.elements.popper.style,n.popper),e.styles=n,e.elements.arrow&&Object.assign(e.elements.arrow.style,n.arrow),function(){Object.keys(e.elements).forEach((function(t){var i=e.elements[t],o=e.attributes[t]||{},r=Object.keys(e.styles.hasOwnProperty(t)?e.styles[t]:n[t]).reduce((function(t,e){return t[e]="",t}),{});mt(i)&&Tt(i)&&(Object.assign(i.style,r),Object.keys(o).forEach((function(t){i.removeAttribute(t)})))}))}},requires:["computeStyles"]}]});const Qt=n("search-list");class Zt{constructor(t,e){this.options=[],this.doc=t,t.addEventListener("click",this.onDocClick.bind(this)),this.element=t.createElement("div"),this.element.classList.add(Qt()),e.viewProps.bindClassModifiers(this.element),this.value=e.value,this.options=e.options,this.noDataText=e.noDataText,this.value.emitter.on("change",this.onValueChange_.bind(this)),this.textView=e.textView,this.textView.inputElement.addEventListener("click",this.onTextInputClick.bind(this)),this.textView.inputElement.addEventListener("input",e.onTextInput),this.element.appendChild(this.textView.element);const n=t.createElement("div");n.classList.add(Qt("m")),n.innerHTML='<svg><path d="M5 7h6l-3 3 z"></path></svg>',this.element.appendChild(n);const i=t.createElement("div");this.selectBox=i,i.classList.add(Qt("select-box"));const o=t.createElement("ul");this.optionsUl=o,o.classList.add(Qt("options")),this.updateOptions(e.options),o.addEventListener("click",(t=>{if(t.target&&t.target instanceof HTMLLIElement){const n=t.target.getAttribute("data-value");if(null!==n){const t=e.options.find((t=>t.value===n));t&&e.onOptionClick(t)}}})),i.appendChild(o),this.popper=Kt(this.textView.inputElement,this.selectBox,{placement:"bottom-start",modifiers:[Object.assign(Object.assign({},Ut),{options:{fallbackPlacements:["top"]}})]}),this.element.appendChild(i),this.update(),this.textView.refresh(),e.viewProps.handleDispose((()=>{this.popper.destroy()}))}onDocClick(t){t.target&&t.target instanceof HTMLElement&&t.target.contains(this.element)&&this.hideSelectOptionsBox()}onTextInputClick(){this.updateOptions(this.options),this.showSelectOptionsBox()}showSelectOptionsBox(){this.selectBox.setAttribute("data-show",""),this.popper.update()}hideSelectOptionsBox(){this.selectBox.removeAttribute("data-show")}updateOptions(t){if(this.optionsUl.innerHTML="",0===t.length){const t=this.doc.createElement("li");return t.innerText=this.noDataText,t.classList.add("no-data"),void this.optionsUl.appendChild(t)}t.forEach((t=>{const e=this.doc.createElement("li");e.innerText=t.label,e.setAttribute("data-value",t.value),this.optionsUl.appendChild(e)}))}update(){this.hideSelectOptionsBox()}onValueChange_(){this.update()}}class te{constructor(t,e){this.value=e.value,this.textValue=e.textValue,this.options=e.options,this.viewProps=e.viewProps,this.debounceFilterOptions=G(this.filterOptions,e.debounceDelay);const n=e.options.find((t=>t.value===e.value.rawValue));n&&(this.textValue.rawValue=n.label);const i=new u(t,{props:e.textProps,viewProps:e.viewProps,value:this.textValue});this.view=new Zt(t,{textProps:e.textProps,viewProps:e.viewProps,textView:i,value:this.value,options:e.options,noDataText:e.noDataText,onTextInput:this.onTextInput.bind(this),onOptionClick:this.onOptionClick.bind(this)}),e.viewProps.handleDispose((()=>{this.debounceFilterOptions.cancel()}))}filterOptions(t=""){const e=this.options.filter((e=>-1!==e.label.toLowerCase().indexOf(t.trim().toLowerCase())));e&&this.view.updateOptions(e)}onTextInput(t){const e=t.currentTarget.value;this.debounceFilterOptions(e)}onOptionClick(t){this.value.rawValue=t.value,this.textValue.rawValue=t.label}}return{plugin:{id:"input-template",type:"input",css:".tp-search-listv_i{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border-width:0;font-family:inherit;font-size:inherit;font-weight:inherit;margin:0;outline:none;padding:0}.tp-search-listv_i{background-color:var(--in-bg);border-radius:var(--elm-br);box-sizing:border-box;color:var(--in-fg);font-family:inherit;height:var(--bld-us);line-height:var(--bld-us);min-width:0;width:100%}.tp-search-listv_i:hover{background-color:var(--in-bg-h)}.tp-search-listv_i:focus{background-color:var(--in-bg-f)}.tp-search-listv_i:active{background-color:var(--in-bg-a)}.tp-search-listv_i:disabled{opacity:.5}.tp-search-listv_m{bottom:0;margin:auto;pointer-events:none;position:absolute;right:2px;top:0}.tp-search-listv_m svg{bottom:0;height:16px;margin:auto;position:absolute;right:0;top:0;width:16px}.tp-search-listv_m svg path{fill:currentColor}.tp-search-listv{position:relative}.tp-search-listv_select-box{display:none;border-radius:var(--bs-br);width:100%;z-index:1001}.tp-search-listv_select-box[data-show]{display:block}.tp-search-listv_options{margin:0;padding:0;list-style-type:none;max-height:240px;overflow:auto;background-color:var(--tp-plugin-select-box-bg-color, var(--in-bg))}.tp-search-listv_options .no-data{cursor:initial;text-align:center;color:var(--tp-plugin-select-no-data-color, #fff)}.tp-search-listv_options li{cursor:pointer;padding:4px 6px;border-radius:var(--bs-br)}.tp-search-listv_options li:hover{background-color:var(--tp-plugin-select-option-bg-hover, #818181)}.tp-search-listv_m{color:var(--button-foreground-color)}",accept:(t,e)=>"search-list"!==e.view&&"string"!=typeof t?null:{initialValue:t,params:e},binding:{reader:t=>t=>"string"==typeof t?t:"",constraint(t){const e=[],n=p(t.params.options);return n&&e.push(n),new s(e)},writer:t=>(t,e)=>{t.write(e)}},controller(t){const e=t.params,n=e.options||{},i=Object.keys(n).map((t=>({label:t,value:n[t]})));return new te(t.document,{value:t.value,textValue:r(""),options:i,noDataText:e.noDataText||"no data",debounceDelay:e.debounceDelay||250,textProps:a.fromObject({formatter:t=>String(t)}),viewProps:t.viewProps})}}}}));