@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 3.39 kB
JavaScript
import{__decorate as o}from"tslib";import{pointDistance as d}from"@expofp/geometry";import{action as m,computed as i,observable as l}from"mobx";import p from"../tools/settings";import{uiState as b}from"./index";export default class s{get boothById(){return new Map(this.booths.map(t=>[t.id,t]))}get boothByExternalId(){return new Map(this.booths.map(t=>[t.externalId,t]))}get boothByName(){return new Map(this.booths.map(t=>[t.name.toLowerCase(),t]))}get boothBySlug(){return new Map(this.booths.map(t=>[t.slug,t]))}get borderWidth(){if(p.boothBorderWidth)return p.boothBorderWidth;if(p.EXPO==="groomexpo")return .4;const t=this.booths.filter(e=>e.rect).map(e=>e.rect.size.width+e.rect.size.height);return t.reduce((e,h)=>e+h,0)/t.length/80}constructor(t){this.booths=[],this.highlightedByExternalIds=[],this.rootStore=t}get bookmarked(){return this.booths.filter(t=>t.bookmarkedDirectly)}getNearestBooth(t){var e=null;const a=this.booths.map(r=>({lineLength:d(t,r.rect.center),name:r.name})).sort((r,u)=>r.lineLength-u.lineLength)[0];return e=this.booths.find(r=>r.name===a.name),e}getBoothAtPoint(t){return this.booths.find(e=>e.rect.containsPoint(t))}findBooth(t){return this.boothByExternalId.get(t)||this.boothByName.get(t.toLowerCase())||this.boothBySlug.get(t)}replaceBookmarked(t){const e=(t||[]).map(r=>this.boothById.get(r)).filter(r=>r),h=new Set(e),a=this.bookmarked.filter(r=>!h.has(r));for(const r of a)r.bookmarkedDirectly=!1;for(const r of e)r.bookmarkedDirectly=!0}}o([l],s.prototype,"booths",void 0),o([l],s.prototype,"highlightedByExternalIds",void 0),o([i({keepAlive:!0})],s.prototype,"boothById",null),o([i({keepAlive:!0})],s.prototype,"boothByExternalId",null),o([i({keepAlive:!0})],s.prototype,"boothByName",null),o([i({keepAlive:!0})],s.prototype,"boothBySlug",null),o([i({keepAlive:!0})],s.prototype,"borderWidth",null),o([i],s.prototype,"bookmarked",null),o([m],s.prototype,"replaceBookmarked",null);export class BoothBase{constructor(){this.bookmarkedDirectly=!1}get bookmarked(){return b.disableBookmarked?!1:this.schedule?.some(t=>t.bookmarked)?!0:this.exhibitors.length>0?!!this.exhibitors.find(t=>t.bookmarked):this.bookmarkedDirectly}get uiState(){return this.store.rootStore.uiState}get fullName(){const t=this.meta?Object.entries(this.meta).filter(([e])=>!e.startsWith("_")).map(([e,h])=>`${e} ${h}`).join(" "):"";return`${this.name} ${t}`.replace(/\s+/g," ").trim()}get visible(){return this.layer?.visible??!0}get hover(){return this.uiState.hoveredBooths.has(this)}get selected(){return this.uiState.selectedBooths.has(this)}get skipDim(){return this.uiState.highlightedBooths.has(this.id.toString())}}o([l],BoothBase.prototype,"layer",void 0),o([l],BoothBase.prototype,"bookmarkedDirectly",void 0),o([i({keepAlive:!0})],BoothBase.prototype,"bookmarked",null),o([i({keepAlive:!0})],BoothBase.prototype,"uiState",null),o([i({keepAlive:!0})],BoothBase.prototype,"fullName",null),o([i({keepAlive:!0})],BoothBase.prototype,"visible",null),o([i({keepAlive:!0})],BoothBase.prototype,"hover",null),o([i({keepAlive:!0})],BoothBase.prototype,"selected",null),o([i({keepAlive:!0})],BoothBase.prototype,"skipDim",null);export class RegularBooth extends BoothBase{constructor(){super(...arguments),this.entity={type:"booth",variant:"regular"}}}export class SpecialBooth extends BoothBase{constructor(){super(...arguments),this.entity={type:"booth",variant:"special"}}}