@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 1.25 kB
JavaScript
import{splitPlatformParams as u}from"@expofp/config";import{createBrowserHistory as w}from"history";import{registerPlanDisposer as g}from"../plan-lifecycle.js";import{eventScopedValue as x}from"../tools/event-scoped-cache.js";import P from"../tools/logger";const t=w();function a(){return window.location.pathname}const c=x(()=>[]);let i="",r=!1,s=!1,f=0,p=()=>{},m;export function getLocationHistory(){return c()}function y(e){if(!i)return a()+e;const n=u(e).search,o=n==="?"?"":n;return a()+(o?`${o}&${i}`:`?${i}`)}export function currentSearch(){return u(t.location.search).search}export function pushQuery(e){!r&&!s&&t.push(y(e))}export function replaceQuery(e){return r||s?!1:(t.replace(y(e)),!0)}export function disableUrlWrites(){g(destroyUrlSync),r=!0}export function initUrlSync(e){g(destroyUrlSync),r||=e.offHistory,p=e.onNavigate,i=u(t.location.search).platform,r||c().push(a()+t.location.search),m=t.listen((n,o)=>{if(h(),r)return;const l=c(),d=a()+n.search;l[l.length-1]!==d&&l.push(d),P.log("history",o,n),o==="POP"&&p()})}export function destroyUrlSync(){r=!1,i="",p=()=>{},c().length=0,h(),m?.(),m=void 0}function h(){s=!1,window.clearTimeout(f)}export function goBack(){s=!0,window.clearTimeout(f),f=window.setTimeout(h,1e3),t.goBack()}