@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 8.7 kB
JavaScript
import{__esDecorate as a,__runInitializers as u}from"tslib";import{action as c,computed as d,observable as g}from"mobx";import{t as p}from"../utils/i18n";import{findBooth as Q,Route as U}from"./RouteStore";let W=(()=>{let n=[],_,S=[],b=[],y,P=[],v=[],k,x=[],R=[],B,F=[],I=[],C,w,O,z,V,E,L,A,N,M,T,j,q,D,$,G,H;return class{static{const e=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;_=[g],y=[g],k=[g],B=[g],C=[d],w=[d],O=[d],z=[d],V=[d],E=[d],L=[d],A=[d],N=[c],M=[c],T=[c],j=[c],q=[c],D=[c],$=[c],G=[c],H=[c],a(this,null,C,{kind:"getter",name:"resolvedBooths",static:!1,private:!1,access:{has:t=>"resolvedBooths"in t,get:t=>t.resolvedBooths},metadata:e},null,n),a(this,null,w,{kind:"getter",name:"stopsCount",static:!1,private:!1,access:{has:t=>"stopsCount"in t,get:t=>t.stopsCount},metadata:e},null,n),a(this,null,O,{kind:"getter",name:"startPointBoothOptions",static:!1,private:!1,access:{has:t=>"startPointBoothOptions"in t,get:t=>t.startPointBoothOptions},metadata:e},null,n),a(this,null,z,{kind:"getter",name:"startPointAutocompleteOptions",static:!1,private:!1,access:{has:t=>"startPointAutocompleteOptions"in t,get:t=>t.startPointAutocompleteOptions},metadata:e},null,n),a(this,null,V,{kind:"getter",name:"title",static:!1,private:!1,access:{has:t=>"title"in t,get:t=>t.title},metadata:e},null,n),a(this,null,E,{kind:"getter",name:"subtitleParts",static:!1,private:!1,access:{has:t=>"subtitleParts"in t,get:t=>t.subtitleParts},metadata:e},null,n),a(this,null,L,{kind:"getter",name:"routeFloors",static:!1,private:!1,access:{has:t=>"routeFloors"in t,get:t=>t.routeFloors},metadata:e},null,n),a(this,null,A,{kind:"getter",name:"currentRouteFloor",static:!1,private:!1,access:{has:t=>"currentRouteFloor"in t,get:t=>t.currentRouteFloor},metadata:e},null,n),a(this,null,N,{kind:"method",name:"setRouteFloor",static:!1,private:!1,access:{has:t=>"setRouteFloor"in t,get:t=>t.setRouteFloor},metadata:e},null,n),a(this,null,M,{kind:"method",name:"launch",static:!1,private:!1,access:{has:t=>"launch"in t,get:t=>t.launch},metadata:e},null,n),a(this,null,T,{kind:"method",name:"launchFromBookmarks",static:!1,private:!1,access:{has:t=>"launchFromBookmarks"in t,get:t=>t.launchFromBookmarks},metadata:e},null,n),a(this,null,j,{kind:"method",name:"launchFromSlugs",static:!1,private:!1,access:{has:t=>"launchFromSlugs"in t,get:t=>t.launchFromSlugs},metadata:e},null,n),a(this,null,q,{kind:"method",name:"buildRoute",static:!1,private:!1,access:{has:t=>"buildRoute"in t,get:t=>t.buildRoute},metadata:e},null,n),a(this,null,D,{kind:"method",name:"setStartPoint",static:!1,private:!1,access:{has:t=>"setStartPoint"in t,get:t=>t.setStartPoint},metadata:e},null,n),a(this,null,$,{kind:"method",name:"removeItem",static:!1,private:!1,access:{has:t=>"removeItem"in t,get:t=>t.removeItem},metadata:e},null,n),a(this,null,G,{kind:"method",name:"reorderItems",static:!1,private:!1,access:{has:t=>"reorderItems"in t,get:t=>t.reorderItems},metadata:e},null,n),a(this,null,H,{kind:"method",name:"close",static:!1,private:!1,access:{has:t=>"close"in t,get:t=>t.close},metadata:e},null,n),a(null,null,_,{kind:"field",name:"items",static:!1,private:!1,access:{has:t=>"items"in t,get:t=>t.items,set:(t,o)=>{t.items=o}},metadata:e},S,b),a(null,null,y,{kind:"field",name:"startPoint",static:!1,private:!1,access:{has:t=>"startPoint"in t,get:t=>t.startPoint,set:(t,o)=>{t.startPoint=o}},metadata:e},P,v),a(null,null,k,{kind:"field",name:"source",static:!1,private:!1,access:{has:t=>"source"in t,get:t=>t.source,set:(t,o)=>{t.source=o}},metadata:e},x,R),a(null,null,B,{kind:"field",name:"excludedVisitedCount",static:!1,private:!1,access:{has:t=>"excludedVisitedCount"in t,get:t=>t.excludedVisitedCount,set:(t,o)=>{t.excludedVisitedCount=o}},metadata:e},F,I),e&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e})}rootStore=u(this,n);items=u(this,S,[]);startPoint=(u(this,b),u(this,P,null));source=(u(this,v),u(this,x,null));excludedVisitedCount=(u(this,R),u(this,F,0));constructor(e){u(this,I),this.rootStore=e}get resolvedBooths(){const e=new Map;return this.startPoint&&e.set(this.startPoint.id,this.startPoint),this.items.forEach(t=>{t.booth&&e.set(t.booth.id,t.booth)}),Array.from(e.values())}get stopsCount(){return this.items.length}get startPointBoothOptions(){return this.rootStore.boothStore.booths}get startPointAutocompleteOptions(){const{exhibitorStore:e}=this.rootStore,t=this.startPointBoothOptions,o=[],r=new Set;return e.exhibitors.forEach(s=>{s.booths.forEach(l=>{r.add(l.id),o.push({value:l.id.toString(),label:`${s.name} - ${l.name}`})})}),t.filter(s=>!r.has(s.id)).forEach(s=>{o.push({value:s.id.toString(),label:s.name})}),o.sort((s,l)=>s.label.localeCompare(l.label,void 0,{sensitivity:"base"}))}get title(){return this.source==="bookmarks"?p("Bookmarks route"):""}get subtitleParts(){const{routeInfo:e}=this.rootStore.routeStore;let t;if(e?.time){const o=e.time;t=o<60?p("< 1 min"):p("~ {{n}} min",{n:Math.round(o/60)})}return{stops:p("{{count}} stops",{count:this.stopsCount}),from:this.startPoint?p("From {{name}}",{name:this.startPoint.name}):void 0,distance:e?e.distance:void 0,travelTime:t}}get routeFloors(){const e=this.rootStore.routeStore.pathLayers;return e.map((t,o)=>{const r=e[o+1],i=t.layer?.basePriority??0,s=r?.layer?.basePriority??0,l=r?s<i?"up":"down":void 0;return{id:t.id,name:t.layer?.shortName,description:t.layer?.description,directionToNext:l}})}get currentRouteFloor(){const e=this.routeFloors,t=this.rootStore.routeStore.currentRouteLayer;if(!e.length)return;if(!t)return e[0]?{id:e[0].id,name:e[0].name}:void 0;const o=e.find(r=>r.description?.toLowerCase()===t.description?.toLowerCase());return o?{id:o.id,name:o.name}:{id:e[0].id,name:e[0].name}}setRouteFloor(e){const t=this.rootStore.routeStore.pathLayers.find(o=>o.id===e.id);t?.layer&&this.rootStore.layerStore.updateVisibility(t.layer,!0)}launch(e,t="custom",o){this.excludedVisitedCount=e.filter(i=>i.type==="exhibitor"&&i.entity.visited).length,this.items=e.filter(i=>i.type==="exhibitor"?!i.entity.visited:!0),this.source=t,this.startPoint=o!==void 0?o:this.detectStartPoint();const{uiState:r}=this.rootStore;r.list={type:"route-planner",source:t},r.details=null,r.menu=!1,this.buildRoute()}launchFromBookmarks(e){const{exhibitorStore:t,eventStore:o,boothStore:r}=this.rootStore,i=[];t.bookmarked.forEach(s=>{i.push({type:"exhibitor",entity:s,booth:s.booths[0]||null})}),r.booths.filter(s=>s.exhibitors.length===0&&s.bookmarkedDirectly).forEach(s=>{i.push({type:"booth",entity:s,booth:s})}),this.launch(i,"bookmarks",e)}launchFromSlugs(e,t){const o=this.resolveSlugs(e);this.launch(o,"custom",t)}resolveSlugs(e){const{exhibitorStore:t,eventStore:o,boothStore:r}=this.rootStore;return e.filter(Boolean).map(i=>{const s=i.toLowerCase(),l=t.exhibitors.find(f=>f.slug?.toLowerCase()===s||f.externalId?.toLowerCase()===s);if(l)return{type:"exhibitor",entity:l,booth:l.booths[0]||null};const m=Q(i);return m?{type:"booth",entity:m,booth:m}:null}).filter(i=>i!==null)}buildRoute(){const e=[];if(this.startPoint&&this.startPoint.name&&e.push(this.startPoint.name),this.items.forEach(h=>{h.booth&&h.booth.name&&e.push(h.booth.name)}),e.length<2){this.rootStore.routeStore.updateRoute([]);return}let t;try{const h=this.rootStore.fp?.getOptimizedRoutes?.(e);t=Array.isArray(h)?h.flatMap(K=>K?.waypoints??[]):[]}catch{t=[]}const o=new Set(e),r=new Set(t),i=e.length>0&&[...o].every(h=>r.has(h));(!t.length||!i)&&(t=e.slice()),this.reorderItemsByNames(t);const s=this.resolvedBooths;if(s.length<2){this.rootStore.routeStore.updateRoute([]);return}const l=s[0],m=s[s.length-1],f=s.slice(1,-1),J=new U(l,m,f);this.rootStore.routeStore.selectRoute(J,!1),this.rootStore.uiState.setIsMultiPointRoute(f.length>0)}reorderItemsByNames(e){const t=this.startPoint?this.startPoint.name:null,o=new Map;this.items.forEach(i=>{const s=i.booth?i.booth.name:null;s&&(o.has(s)||o.set(s,[]),o.get(s).push(i))});const r=[];e.forEach(i=>{if(i!==t){const s=o.get(i);s&&s.length>0&&r.push(...s.splice(0))}}),this.items=r}detectStartPoint(){const{boothStore:e,poiTypeStore:t}=this.rootStore,o=["entrance","entrances"],r=t.poiTypes.find(i=>o.includes(i.name.toLowerCase()));return r&&e.booths.find(i=>i.poiTypeId===r.id)||null}setStartPoint(e){this.startPoint=e,this.buildRoute()}removeItem(e){this.items.splice(e,1),this.buildRoute()}reorderItems(e,t){const[o]=this.items.splice(e,1);this.items.splice(t,0,o),this.buildRoute()}close(){this.items=[],this.startPoint=null,this.source=null,this.excludedVisitedCount=0,this.rootStore.uiState.details=null,this.rootStore.uiState.list={type:"search",text:"",focused:!1},this.rootStore.routeStore.selectRoute(null,!1)}}})();export default W;