jodit-pro
Version:
PRO Version of Jodit Editor
2 lines (1 loc) • 2.51 kB
JavaScript
var x=Object.defineProperty;var f=(a,e)=>x(a,"name",{value:e,configurable:!0});var u,v=function(a,e,t,l){var s=arguments.length,i=s<3?e:l===null?l=Object.getOwnPropertyDescriptor(e,t):l,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,l);else for(var m=a.length-1;m>=0;m--)(o=a[m])&&(i=(s<3?o(i):s>3?o(e,t,i):o(e,t))||i);return s>3&&i&&Object.defineProperty(e,t,i),i};import{ListReconciler as _}from"../../../core/ui/helpers/index.js";import{AutocompleteItem as g}from"./item.js";import{component as M,watch as I}from"jodit/esm/core/decorators/index.js";import{UIGroup as O}from"jodit/esm/core/ui/group/group.js";let d=(u=class extends O{constructor(){super(...arguments),this.elements=[],this.currentSelection=-1,this.__previousList=[],this.itemsMap=new Map}className(){return"Autocomplete"}onChangeSelection(){var e,t;this.elements.forEach(l=>l.setMod("active",!1)),(e=this.elements[this.currentSelection])===null||e===void 0||e.setMod("active",!0),(t=this.elements[this.currentSelection])===null||t===void 0||t.container.scrollIntoView(!1)}build(e){var t;const l=(t=this.elements[this.currentSelection])===null||t===void 0?void 0:t.item.value,s=f(n=>n.value,"getId"),i=_.reconcile(this.__previousList,e,{getId:s}),o=new Set;i.toRemove.forEach(n=>{const r=s(n);if(o.has(r))return;o.add(r);const c=this.itemsMap.get(r);c&&(this.elements.indexOf(c)!==-1&&(this.remove(c),c.destruct()),this.itemsMap.delete(n.value))}),i.toCreate.forEach(n=>{const r=s(n);if(o.has(r))return;o.add(r);const c=new g(this.jodit,n,p=>{this.currentSelection=e.findIndex(S=>s(S)===p),this.select()});this.itemsMap.set(r,c);const h=e.indexOf(n);this.append(c,h)}),i.toUpdate.forEach(({newItem:n,index:r})=>{const c=s(n);if(o.has(c))return;o.add(c);const h=this.itemsMap.get(c);h&&(h.item=n,this.elements.indexOf(h)!==r&&r<this.elements.length&&(this.remove(h),this.append(h,r)))});const m=this.currentSelection;this.currentSelection=Math.max(0,e.findIndex(n=>s(n)===l)),m===this.currentSelection&&this.onChangeSelection(),this.__previousList=[...e]}selectNext(){this.currentSelection+1<=this.elements.length-1?this.currentSelection+=1:this.currentSelection=0}selectPrevious(){this.currentSelection-1>=0?this.currentSelection-=1:this.currentSelection=this.elements.length-1}select(){this.j.e.fire("select.autocomplete",this.elements[this.currentSelection].item)}},f(u,"Autocomplete"),u);v([I("currentSelection")],d.prototype,"onChangeSelection",null),d=v([M],d);export{d as Autocomplete};