UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 9.67 kB
import{__esDecorate as l,__runInitializers as y}from"tslib";import{action as h,observable as A,reaction as F}from"mobx";import{PREFIXES as $}from"../store/search-buttons/constants";import a from"../tools/logger";import{decodeString as X,decodeStringArray as M,encodeString as G,encodeStringArray as N,toLowerCaseArray as m,toLowerCaseString as k}from"../utils/urlEncoding";const d={CATEGORIES:"categories",POI_TYPE:"poiType",POI_TYPES:"poiTypes",EXHIBITORS:"exhibitors"};let H=(()=>{let n=[],f,T=[],S=[],P,L=[],I=[],C,_,R,b,w,O,U,x,E,z;return class{static{const t=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;f=[A],P=[A],C=[h],_=[h],R=[h],b=[h],w=[h],O=[h],U=[h],x=[h],E=[h],z=[h],l(this,null,C,{kind:"method",name:"initialize",static:!1,private:!1,access:{has:e=>"initialize"in e,get:e=>e.initialize},metadata:t},null,n),l(this,null,_,{kind:"method",name:"parseURLFilters",static:!1,private:!1,access:{has:e=>"parseURLFilters"in e,get:e=>e.parseURLFilters},metadata:t},null,n),l(this,null,R,{kind:"method",name:"applyFiltersToStore",static:!1,private:!1,access:{has:e=>"applyFiltersToStore"in e,get:e=>e.applyFiltersToStore},metadata:t},null,n),l(this,null,b,{kind:"method",name:"updateURLFromFilters",static:!1,private:!1,access:{has:e=>"updateURLFromFilters"in e,get:e=>e.updateURLFromFilters},metadata:t},null,n),l(this,null,w,{kind:"method",name:"setCategories",static:!1,private:!1,access:{has:e=>"setCategories"in e,get:e=>e.setCategories},metadata:t},null,n),l(this,null,O,{kind:"method",name:"setPoiType",static:!1,private:!1,access:{has:e=>"setPoiType"in e,get:e=>e.setPoiType},metadata:t},null,n),l(this,null,U,{kind:"method",name:"setPoiTypes",static:!1,private:!1,access:{has:e=>"setPoiTypes"in e,get:e=>e.setPoiTypes},metadata:t},null,n),l(this,null,x,{kind:"method",name:"clearAllFilters",static:!1,private:!1,access:{has:e=>"clearAllFilters"in e,get:e=>e.clearAllFilters},metadata:t},null,n),l(this,null,E,{kind:"method",name:"focusOnFilteredBooths",static:!1,private:!1,access:{has:e=>"focusOnFilteredBooths"in e,get:e=>e.focusOnFilteredBooths},metadata:t},null,n),l(this,null,z,{kind:"method",name:"openExhibitorsList",static:!1,private:!1,access:{has:e=>"openExhibitorsList"in e,get:e=>e.openExhibitorsList},metadata:t},null,n),l(null,null,f,{kind:"field",name:"currentFilters",static:!1,private:!1,access:{has:e=>"currentFilters"in e,get:e=>e.currentFilters,set:(e,r)=>{e.currentFilters=r}},metadata:t},T,S),l(null,null,P,{kind:"field",name:"isInitialized",static:!1,private:!1,access:{has:e=>"isInitialized"in e,get:e=>e.isInitialized,set:(e,r)=>{e.isInitialized=r}},metadata:t},L,I),t&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:t})}rootStore=y(this,n);currentFilters=y(this,T,{categories:[],poiType:null,poiTypes:[],exhibitors:!1});isInitialized=(y(this,S),y(this,L,!1));constructor(t){y(this,I),this.rootStore=t,this.setupReactions()}initialize(){this.parseURLFilters(),this.applyFiltersToStore(),this.isInitialized=!0,a.log("URLFilterManager initialized with filters:",this.currentFilters)}parseURLFilters(){const t=new URLSearchParams(window.location.search),e=t.get(d.CATEGORIES),r=e?M(e):[],i=t.get(d.POI_TYPE),s=i?X(i):null,o=t.get(d.POI_TYPES),c=o?M(o):[],p=t.get(d.EXHIBITORS),u=p==="true"||p==="",v=c.filter(g=>{if(!g)return!1;const B=this.rootStore.poiTypeStore.poiTypes.some(Y=>Y.name.toLowerCase()===g.toLowerCase());return B||a.warn(`POI type not found in data: ${g}`),B});r.length>0&&(s||v.length>0)?(a.warn("URL contains both categories and POI types. Clearing POI types."),this.currentFilters={categories:r,poiType:null,poiTypes:[],exhibitors:u}):this.currentFilters={categories:r,poiType:s,poiTypes:v,exhibitors:u},a.log("URLFilterManager parsed filters:",{categories:r,poiType:s,poiTypes:c,exhibitors:u}),this.validateFilters(this.currentFilters)}applyFiltersToStore(){const{uiState:t,categoryFilterStore:e,searchButtonsStore:r}=this.rootStore;if(this.currentFilters.categories.length>0){const i=this.currentFilters.categories.map(s=>this.rootStore.categoryStore.categories.find(o=>o.name.toLowerCase()===s.toLowerCase())).filter(s=>s!==void 0);i.length>0?(t.selectedCategoryFilters=i,e.state.selectedItems=i.map(s=>({id:s.id,name:s.name})),t.categoryFilterOpen=!0,a.log("URLFilterManager applied categories:",i.map(s=>s.name)),setTimeout(()=>{this.focusOnFilteredBooths(),this.rootStore.searchStore.setFocused(!0)},100)):a.warn("URLFilterManager: no categories found for names:",this.currentFilters.categories)}if(this.currentFilters.poiType){const i=this.rootStore.poiTypeStore.poiTypes.find(s=>s.name.toLowerCase()===this.currentFilters.poiType.toLowerCase());i?(t.selectedPoiTypeFilters=[i],r.setPoiFilterId(`${$.POI_TYPE}${i.id}`),a.log("URLFilterManager applied POI type:",i.name),setTimeout(()=>{this.focusOnFilteredBooths(),this.rootStore.searchStore.setFocused(!0)},100)):a.warn("URLFilterManager: no POI type found for name:",this.currentFilters.poiType)}if(this.currentFilters.poiTypes.length>0){const i=this.currentFilters.poiTypes.map(s=>s?this.rootStore.poiTypeStore.poiTypes.find(o=>o.name.toLowerCase()===s.toLowerCase()):null).filter(s=>s!=null);i.length>0?(t.selectedPoiTypeFilters=i,a.log("URLFilterManager applied POI types:",i.map(s=>s.name)),setTimeout(()=>{this.focusOnFilteredBooths(),this.rootStore.searchStore.setFocused(!0)},100)):(a.warn("URLFilterManager: no POI types found for names:",this.currentFilters.poiTypes),this.currentFilters.poiTypes=[])}this.currentFilters.exhibitors&&this.openExhibitorsList()}updateURLFromFilters(){const{uiState:t}=this.rootStore,e=new URLSearchParams;if(t.selectedCategoryFilters.length>0){const i=t.selectedCategoryFilters.map(o=>o.name.toLowerCase()),s=N(i);s&&e.set(d.CATEGORIES,s)}if(t.selectedPoiTypeFilters.length>0&&t.selectedCategoryFilters.length===0)if(t.selectedPoiTypeFilters.length===1){const i=t.selectedPoiTypeFilters[0].name.toLowerCase();if(i){const s=G(i);s&&e.set(d.POI_TYPE,s)}}else{const i=t.selectedPoiTypeFilters.map(o=>o.name.toLowerCase()),s=N(i);s&&e.set(d.POI_TYPES,s)}this.currentFilters.exhibitors&&t.selectedCategoryFilters.length===0&&t.selectedPoiTypeFilters.length===0&&e.set(d.EXHIBITORS,"true");const r=window.location.pathname+(e.toString()?`?${e.toString()}`:"");window.history.replaceState({},"",r),this.currentFilters={categories:t.selectedCategoryFilters.length>0?t.selectedCategoryFilters.map(i=>i.name):[],poiType:t.selectedPoiTypeFilters.length===1&&t.selectedCategoryFilters.length===0?t.selectedPoiTypeFilters[0].name:null,poiTypes:t.selectedPoiTypeFilters.length>1&&t.selectedCategoryFilters.length===0?t.selectedPoiTypeFilters.map(i=>i.name):[],exhibitors:this.currentFilters.exhibitors}}setCategories(t){this.currentFilters.categories=m(t),this.currentFilters.poiType=null,this.isInitialized&&this.updateURLFromFilters()}setPoiType(t){this.currentFilters.poiType=k(t),this.currentFilters.poiTypes=[],this.currentFilters.categories=[],this.isInitialized&&this.updateURLFromFilters()}setPoiTypes(t){this.currentFilters.poiTypes=m(t),this.currentFilters.poiType=null,this.currentFilters.categories=[],this.isInitialized&&this.updateURLFromFilters()}clearAllFilters(){this.currentFilters={categories:[],poiType:null,poiTypes:[],exhibitors:!1};const{uiState:t}=this.rootStore;t.categoryFilterOpen=!1,this.updateURLFromFilters()}getCurrentFilters(){return{...this.currentFilters}}setupReactions(){F(()=>this.rootStore.uiState.selectedCategoryFilters,t=>{if(this.isInitialized&&t.length>0){const e=m(t.map(r=>r.name));this.setCategories(e)}}),F(()=>this.rootStore.uiState.selectedPoiTypeFilters,t=>{if(this.isInitialized&&t.length>0)if(t.length===1){const e=k(t[0].name);e&&this.setPoiType(e)}else{const e=m(t.map(r=>r.name));this.setPoiTypes(e)}})}validateFilters(t){if(t.categories.length>0&&(t.poiType||t.poiTypes.length>0))return a.warn("Categories and POI types cannot be active simultaneously"),!1;if(t.poiType&&t.poiTypes.length>0)return a.warn("Both single POI type and multiple POI types cannot be active simultaneously"),!1;for(const e of t.categories)if(!this.getCategoryIdByName(e))return a.warn(`Category not found: ${e}`),!1;if(t.poiType&&!this.getPoiTypeIdByName(t.poiType))return a.warn(`POI type not found: ${t.poiType}`),!1;for(const e of t.poiTypes)if(!this.getPoiTypeIdByName(e))return a.warn(`POI type not found: ${e}`),!1;return!0}getCategoryIdByName(t){const e=this.rootStore.categoryStore.categories.find(r=>r.name.toLowerCase()===t.toLowerCase());return e?e.id:null}getPoiTypeIdByName(t){const e=this.rootStore.poiTypeStore.poiTypes.find(r=>r.name.toLowerCase()===t.toLowerCase());return e?e.id:null}focusOnFilteredBooths(){if(!this.rootStore.layerStore.layersLoaded){F(()=>this.rootStore.layerStore.layersLoaded,()=>{this.focusOnFilteredBooths()},{fireImmediately:!1});return}const{uiState:t,exhibitorStore:e,boothStore:r}=this.rootStore;let i=[];if(t.selectedCategoryFilters.length>0){const o=e.exhibitors.filter(c=>t.selectedCategoryFilters.some(p=>c.categories.some(u=>u.id===p.id)));i=r.booths.filter(c=>o.some(p=>p.id===c.exhibitors[0]?.id))}if(t.selectedPoiTypeFilters.length>0){const o=r.booths.filter(c=>t.selectedPoiTypeFilters.some(p=>c.poiTypeId===p.id));i.length>0?i=i.filter(c=>o.some(p=>p.id===c.id)):i=o}const s=i.filter(o=>o.visible);s.length>0?(t.moveToBooths=s,this.rootStore.moveToList(s)):i.length>0&&(this.rootStore.showMap(),this.rootStore.moveToList(i))}openExhibitorsList(){const{uiState:t}=this.rootStore;t.list={type:"exhibitors",text:"",focused:!1},setTimeout(()=>{this.rootStore.searchStore.setFocused(!0)},100),a.log("URLFilterManager opened exhibitors list")}}})();export{H as URLFilterManager};