UNPKG

manuel

Version:

A super customizable VDOM autocomplete with *production ready* defaults.

2 lines (1 loc) 5.11 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).manuel=e()}}(function(){return function e(n,t,r){function o(u,s){if(!t[u]){if(!n[u]){var d="function"==typeof require&&require;if(!s&&d)return d(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return o(t||e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,n,t){function r(e){return function(n){var t=e(n.children[1]);return void 0!==t&&(n.children[1]=t),n}}function o(e){var n=e.hyperscript,t=e.get,r=e.set;return function(e,o){var u=o||{},c=e.list,l=e.input,a=e.chosen,m=e.open,v=function(){return t(c)},h=function(){return t(l)},p=function(){return t(a)},g=function(){return t(m)},b=e.highlighted,N=h(),y=void 0!==u.minChars?u.minChars:2,k=void 0!==u.maxItems?u.maxItems:10,w=void 0!==u.sort?u.sort:s,I=void 0!==u.filter?u.filter:i,T=void 0!==u.filteredList?u.filteredList:v().filter(function(e){return I(N,e)}).sort(w).slice(0,k);null!=t(b)&&-1==T.indexOf(t(b))&&r(b,null),null!=p()&&p()!=N&&r(a,null);var x={filteredList:T,minChars:y,maxItems:k,sort:w,filter:I,eventNames:void 0!==u.eventNames?u.eventNames:{oninput:"oninput",onfocus:"onfocus",onblur:"onblur",onkeydown:"onkeydown",onmousedown:"onmousedown"},showingDrawer:void 0!==u.showingDrawer?u.showingDrawer:g()&&N.length>=y&&T.length>0,choose:void 0!==u.choose?u.choose:function(e){h()!=e&&r(l,e),p()!=e&&r(a,e),x.close()},clickItem:void 0!==u.clickItem?u.clickItem:function(e){return x.choose(e)},PATTERN_INPUT:void 0!==u.PATTERN_INPUT?u.PATTERN_INPUT:N?new RegExp(N,"gi"):null,mark:void 0!==u.mark?u.mark:function(e){return n("mark",{},[e])},highlight:void 0!==u.highlight?u.highlight:function(e){var n=null!=x.PATTERN_INPUT?e.match(x.PATTERN_INPUT):null,t={buffer:e,output:[]},r=null!=n?n.reduce(function(e,n){var t=e.buffer.indexOf(n);return{buffer:e.buffer.slice(t+n.length),output:e.output.concat(0===t?[]:e.buffer.slice(0,t),[x.mark(e.buffer.slice(t,t+n.length))])}},t):{output:[e],buffer:""};return r.output.concat(r.buffer||[])},oninput:void 0!==u.oninput?u.oninput:function(e){var n=e.currentTarget.value;h()!=n&&r(l,n),g()||r(m,!0)},onfocus:void 0!==u.onfocus?u.onfocus:function(){g()||r(m,!0)},close:void 0!==u.close?u.close:function(){g()&&r(m,!1)},onblur:void 0!==u.onblur?u.onblur:function(){x.close()},renderInput:void 0!==u.renderInput?u.renderInput:function(){return n("input",[["value",N],[x.eventNames.oninput,x.oninput],[x.eventNames.onfocus,x.onfocus],[x.eventNames.onblur,x.onblur]].reduce(d,{}),[])},itemClassNames:void 0!==u.itemClassNames?u.itemClassNames:function(e){return e==t(b)?"highlight":""},renderItem:void 0!==u.renderItem?u.renderItem:function(e,t){return n("li",[["className",t.itemClassNames(e,t)],[t.eventNames.onmousedown,function(n){t.clickItem(e),n.stopPropagation()}]].reduce(d,{}),t.highlight(e))},renderItems:void 0!==u.renderItems?u.renderItems:function(e){return n("ul",{},e.filteredList.map(function(n){return e.renderItem(n,e)}))},classNames:void 0!==u.classNames?u.classNames:function(){return["manuel-complete"].concat(x.showingDrawer?["open"]:[],N.length>0?["not-empty"]:[],v().length>0?["loaded"]:[]).join(" ")},renderRoot:void 0!==u.renderRoot?u.renderRoot:function(e){return n("div",[["className",e.classNames()],[e.eventNames.onkeydown,e.onkeydown]].reduce(d,{}),[e.renderInput(e),e.renderItems(e)])},keyboardSubmit:void 0!==u.keyboardSubmit?u.keyboardSubmit:f.submit,keyboardDismiss:void 0!==u.keyboardDismiss?u.keyboardDismiss:f.dismiss,keyboardNavigate:void 0!==u.keyboardNavigate?u.keyboardNavigate:f.navigate,onkeydown:void 0!==u.onkeydown?u.onkeydown:function(e){var n=x.keyboardSubmit(e.keyCode,t(b)),o=x.keyboardDismiss(e.keyCode),i=e.shiftKey?[]:x.keyboardNavigate(x.showingDrawer,t(b),x.filteredList,e.keyCode);n.map(x.choose),i.map(function(e){return r(b,e)}),o.map(x.close),n.length+o.length+i.length>0&&e.preventDefault()}};return x.renderRoot(x)}}var i=function(e,n){return!e.trim().length||RegExp(u(e.trim()),"i").test(n)},u=function(e){return e.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&")},s=function(e,n){return e.length!==n.length?e.length-n.length:e<n?-1:1},d=function(e,n){return e[n[0]]=n[1],e},f={submit:function(e,n){return 13==e&&n?[n]:[]},dismiss:function(e){return 27==e?[!0]:[]},navigate:function(e,n,t,r){var o=t.indexOf(n),i=-1==o,u=t.length-1,s=o>=-1,d=o+1,f=o-1;return!e||38!=r&&40!=r?[]:38!=r||!i&&0!=o?38==r&&s?[t[f]]:40!=r||!i&&o!=u?[t[d]]:[t[0]]:[t[u]]}};n.exports=o,o.queries={listItems:function(e){return r(function(n){var t=e(n.children);return void 0!==t&&(n.children=t),n})},list:r,root:function(e){return function(n){var t=e(n);return void 0!==t?t:n}},input:function(e){return function(n){var t=e(n.children[0]);return void 0!==t&&(n.children[0]=t),n}}}},{}]},{},[1])(1)});